Module: BubbleWrap::Persistence

Defined in:
motion/core/persistence.rb

Class Method Summary (collapse)

Class Method Details

+ (Object) [](key)



15
16
17
18
19
20
21
22
23
# 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

+ (Object) []=(key, value)



10
11
12
13
# File 'motion/core/persistence.rb', line 10

def []=(key, value)
  storage.setObject(value, forKey: storage_key(key))
  storage.synchronize
end

+ (Object) app_key



6
7
8
# File 'motion/core/persistence.rb', line 6

def app_key
  @app_key ||= BubbleWrap::App.identifier
end

+ (Object) delete(key)



32
33
34
35
36
37
# 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

+ (Object) merge(values)



25
26
27
28
29
30
# 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

+ (Object) storage



39
40
41
# File 'motion/core/persistence.rb', line 39

def storage
  NSUserDefaults.standardUserDefaults
end

+ (Object) storage_key(key)



43
44
45
# File 'motion/core/persistence.rb', line 43

def storage_key(key)
  "#{app_key}_#{key}"
end