module BubbleWrap::Persistence

Public Instance Methods

[](key) click to toggle source
# File motion/core/persistence.rb, line 15
def [](key)
  value = storage.objectForKey storage_key(key)

  # RubyMotion currently has a bug where the strings returned from
  # standardUserDefaults are missing some methods (e.g. to_data).
  # And because the returned object is slightly different than a normal
  # String, we can't just use `value.is_a?(String)`
  value.class.to_s == 'String' ? value.dup : value
end
[]=(key, value) click to toggle source
# File motion/core/persistence.rb, line 10
def []=(key, value)
  storage.setObject(value, forKey: storage_key(key))
  storage.synchronize
end
all() click to toggle source
# File motion/core/persistence.rb, line 47
def all
  hash = storage.dictionaryRepresentation.select{|k,v| k.start_with?(app_key) }
  new_hash = {}
  hash.each do |k,v|
    new_hash[k.sub("#{app_key}_", '')] = v
  end
  new_hash
end
app_key() click to toggle source
# File motion/core/persistence.rb, line 6
def app_key
  @app_key ||= BubbleWrap::App.identifier
end
delete(key) click to toggle source
# File motion/core/persistence.rb, line 32
def delete(key)
  value = storage.objectForKey storage_key(key)
  storage.removeObjectForKey(storage_key(key))
  storage.synchronize
  value
end
merge(values) click to toggle source
# File motion/core/persistence.rb, line 25
def merge(values)
  values.each do |key, value|
    storage.setObject(value, forKey: storage_key(key))
  end
  storage.synchronize
end
storage() click to toggle source
# File motion/core/persistence.rb, line 39
def storage
  NSUserDefaults.standardUserDefaults
end
storage_key(key) click to toggle source
# File motion/core/persistence.rb, line 43
def storage_key(key)
  "#{app_key}_#{key}"
end