Module: BubbleWrap::Persistence
- Defined in:
- motion/core/persistence.rb
Class Method Summary collapse
- .[](key) ⇒ Object
- .[]=(key, value) ⇒ Object
- .app_key ⇒ Object
- .merge(values) ⇒ Object
- .storage ⇒ Object
- .storage_key(key) ⇒ Object
Class Method Details
.[](key) ⇒ Object
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 |
.[]=(key, value) ⇒ Object
10 11 12 13 |
# File 'motion/core/persistence.rb', line 10 def []=(key, value) storage.setObject(value, forKey: storage_key(key)) storage.synchronize end |
.app_key ⇒ Object
6 7 8 |
# File 'motion/core/persistence.rb', line 6 def app_key @app_key ||= BubbleWrap::App.identifier end |
.merge(values) ⇒ Object
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 |
.storage ⇒ Object
32 33 34 |
# File 'motion/core/persistence.rb', line 32 def storage NSUserDefaults.standardUserDefaults end |
.storage_key(key) ⇒ Object
36 37 38 |
# File 'motion/core/persistence.rb', line 36 def storage_key(key) app_key + '_' + key.to_s end |