motion-settings 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +26 -100
- data/lib/motion-settings.rb +8 -6
- data/lib/project/settings.rb +40 -0
- metadata +33 -27
- data/.gitignore +0 -18
- data/Gemfile +0 -3
- data/LICENSE +0 -22
- data/Rakefile +0 -2
- data/lib/motion-settings/rmsettable.rb +0 -97
- data/lib/motion-settings/rmsettings.rb +0 -182
- data/lib/motion-settings/version.rb +0 -5
- data/motion-settings.gemspec +0 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 26cc2c5fbdbca6bfd6df4c77cd26260329d75f95
|
4
|
+
data.tar.gz: d5d8aba7003e01eef38b9c65afe66b9a88cf5edd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3c62be2446ebff5b8981abfc1f538b738716c991647d7f2527b78d1b7d76a6d956cf001b2c48f32a68865a32e659c12edfc57f0b5aeac0994218a5bdb198985
|
7
|
+
data.tar.gz: f8642f1bfa1b2348a57da1176852c1982b8374e11638407abb965b1d62e23deff49acab535e283a9df1100fbd45c59f21e8488f5b53865eae821b7bdd55b8789
|
data/README.md
CHANGED
@@ -1,126 +1,52 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# motion-settings
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/motion-settings.svg)](http://badge.fury.io/rb/motion-settings)
|
3
|
+
[![Build Status](https://travis-ci.org/andrewhavens/motion-settings.svg?branch=master)](https://travis-ci.org/andrewhavens/motion-settings)
|
3
4
|
|
4
|
-
|
5
|
+
Easily store and retrieve your user's preferences and settings using `NSUserDefaults`.
|
5
6
|
|
6
|
-
|
7
|
-
------------
|
7
|
+
Note that `NSUserDefaults` is not designed for secure data storage (passwords, tokens, etc). If you need to store data securely, use [`motion-keychain`](https://github.com/IconoclastLabs/motion-keychain).
|
8
8
|
|
9
|
-
|
9
|
+
## Installation
|
10
10
|
|
11
|
-
|
11
|
+
Add this line to your application's `Gemfile`:
|
12
12
|
|
13
|
-
|
13
|
+
gem 'motion-settings', github: 'andrewhavens/motion-settings'
|
14
14
|
|
15
|
-
|
16
|
-
-----
|
15
|
+
And then execute:
|
17
16
|
|
18
|
-
|
17
|
+
$ bundle
|
19
18
|
|
20
|
-
|
19
|
+
## Usage
|
21
20
|
|
22
|
-
|
23
|
-
class AppDelegate
|
24
|
-
include RMSettable
|
25
|
-
|
26
|
-
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
27
|
-
rm_settable :name, :background_color
|
28
|
-
|
29
|
-
...
|
30
|
-
```
|
31
|
-
|
32
|
-
In its simplest form, the `rm_settable` function is called with a list of symbols for the settings your app will save to the NSUserDefaults.
|
21
|
+
Store data:
|
33
22
|
|
34
23
|
```ruby
|
35
|
-
|
24
|
+
Settings.set :favorite_color, 'green'
|
36
25
|
```
|
37
26
|
|
38
|
-
|
27
|
+
Retrieve data:
|
39
28
|
|
40
29
|
```ruby
|
41
|
-
|
30
|
+
favorite_color = Settings.get :favorite_color
|
42
31
|
```
|
43
32
|
|
44
|
-
|
45
|
-
|
46
|
-
### Options
|
47
|
-
|
48
|
-
Additionally, you can include a hash of options to affect the way RMSettings works.
|
33
|
+
Remove an individual value:
|
49
34
|
|
50
35
|
```ruby
|
51
|
-
|
36
|
+
Settings.destroy :favorite_color
|
52
37
|
```
|
38
|
+
Remove ALL data:
|
53
39
|
|
54
40
|
```ruby
|
55
|
-
|
56
|
-
```
|
57
|
-
|
58
|
-
#### Available Options
|
59
|
-
* `autosave` _(true)_
|
60
|
-
|
61
|
-
By default, settings are synchronized to the device as soon as
|
62
|
-
it is updated. However, if you are updating a lot of items at once
|
63
|
-
or would prefer to manually call save on the settings object, set
|
64
|
-
this to false. Be aware that iOS will still save the settings
|
65
|
-
periodically without being explicitly called.
|
66
|
-
|
67
|
-
Regardless of this setting, settings will also be saved when
|
68
|
-
`applicationDidEnterBackground` or `applicationWillTerminate` is called
|
69
|
-
on the app. To prevent this behaviour, you must override these methods
|
70
|
-
in your `app_delegate.rb`.
|
71
|
-
|
72
|
-
* `default_type` _(:object)_
|
73
|
-
|
74
|
-
Items are saved as objects. You many also specify a particular
|
75
|
-
type when you declare the setting names. With this setting you
|
76
|
-
may override the default type for all settings.
|
77
|
-
|
78
|
-
* `lenient_keys` _(false)_
|
79
|
-
|
80
|
-
If you don't want to declare any or all of the settings you will
|
81
|
-
be storing, set this to true. Any setting not explicitly declared
|
82
|
-
will still be stored and retrieved as the default setting type.
|
83
|
-
|
84
|
-
### Reading and Writing User Settings
|
85
|
-
|
86
|
-
A method named `settings` is added to the application's delegate and supplies a simple interface to the user settings.
|
87
|
-
|
88
|
-
```ruby
|
89
|
-
# write a setting
|
90
|
-
UIApplication.sharedApplication.delegate.settings.name = 'Karl Pilkington'
|
91
|
-
UIApplication.sharedApplication.delegate.settings[:head_shape] = 'Orange'
|
92
|
-
|
93
|
-
# read a setting
|
94
|
-
@name = UIApplication.sharedApplication.delegate.settings.name
|
95
|
-
@head_shape = UIApplication.sharedApplication.delegate.settings[:head_shape]
|
96
|
-
|
97
|
-
# check a setting's boolean value or blankness
|
98
|
-
UIApplication.sharedApplication.delegate.settings.name?
|
99
|
-
|
100
|
-
# reset a setting to its default (also aliased as 'reset' or 'remove')
|
101
|
-
UIApplication.sharedApplication.delegate.settings.delete :name
|
41
|
+
Settings.clear
|
102
42
|
```
|
103
43
|
|
104
|
-
|
105
|
-
------
|
106
|
-
|
107
|
-
Convenience subclasses are provided for `UIViewController` and `UIView` called `RMViewController` and `RMView`. If you derive your views and controllers form these classes you will have even easier access to the application's settings.
|
108
|
-
|
109
|
-
```ruby
|
110
|
-
class MyCoolView < RMView
|
111
|
-
|
112
|
-
def headClassifier
|
113
|
-
if !settings.head_shape? and settings.username =~ /karl\spilkington/i
|
114
|
-
settings.head_shape = 'Orange'
|
115
|
-
end
|
116
|
-
end
|
117
|
-
...
|
118
|
-
```
|
44
|
+
Review [the spec](https://github.com/andrewhavens/motion-settings/blob/master/spec/main_spec.rb) for more usage examples.
|
119
45
|
|
120
|
-
|
121
|
-
-----
|
122
|
-
* Add tests
|
123
|
-
* Add error reporting
|
124
|
-
* Check that passed data types are valid
|
125
|
-
* Add support for setting default value at declaration
|
46
|
+
## Contributing
|
126
47
|
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/lib/motion-settings.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
|
+
unless defined?(Motion::Project::Config)
|
4
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
5
|
+
end
|
6
|
+
|
7
|
+
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
3
8
|
Motion::Project::App.setup do |app|
|
4
|
-
|
5
|
-
|
6
|
-
app.files << File.expand_path(File.dirname(__FILE__) + '/motion-settings/rmsettings.rb')
|
7
|
-
end
|
8
|
-
end
|
9
|
+
app.files.unshift(Dir.glob(File.join(lib_dir_path, "project/**/*.rb")))
|
10
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class Settings < NSUserDefaults
|
2
|
+
attr_reader :name
|
3
|
+
attr_accessor :value
|
4
|
+
|
5
|
+
def self.get(name)
|
6
|
+
new(name).fetch.value
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.set(name, value)
|
10
|
+
new(name).tap{|s| s.value = value; s.save }.value
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.destroy(name)
|
14
|
+
new(name).destroy
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.clear
|
18
|
+
NSUserDefaults.standardUserDefaults.setPersistentDomain(NSDictionary.dictionary, forName: NSBundle.mainBundle.bundleIdentifier)
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(name)
|
22
|
+
@name = name.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
def save
|
26
|
+
NSUserDefaults.standardUserDefaults[name] = self.value
|
27
|
+
NSUserDefaults.standardUserDefaults.synchronize
|
28
|
+
end
|
29
|
+
|
30
|
+
def fetch
|
31
|
+
self.value = NSUserDefaults.standardUserDefaults[name]
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def destroy
|
36
|
+
self.value = nil
|
37
|
+
NSUserDefaults.standardUserDefaults.removeObjectForKey name
|
38
|
+
save
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,58 +1,64 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-settings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
|
-
-
|
9
|
-
-
|
7
|
+
- Andrew Havens
|
8
|
+
- Jamon Holmgren
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
14
|
-
dependencies:
|
15
|
-
|
16
|
-
|
12
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
description: A RubyMotion gem to help you easily store and retrieve your user's preferences
|
29
|
+
and settings using NSUserDefaults.
|
17
30
|
email:
|
18
|
-
-
|
19
|
-
- aaron@showtimefu.com
|
31
|
+
- email@andrewhavens.com
|
20
32
|
executables: []
|
21
33
|
extensions: []
|
22
34
|
extra_rdoc_files: []
|
23
35
|
files:
|
24
|
-
- .gitignore
|
25
|
-
- Gemfile
|
26
|
-
- LICENSE
|
27
36
|
- README.md
|
28
|
-
- Rakefile
|
29
37
|
- lib/motion-settings.rb
|
30
|
-
- lib/
|
31
|
-
|
32
|
-
|
33
|
-
-
|
34
|
-
|
35
|
-
licenses: []
|
38
|
+
- lib/project/settings.rb
|
39
|
+
homepage: https://github.com/andrewhavens/motion-settings
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata: {}
|
36
43
|
post_install_message:
|
37
44
|
rdoc_options: []
|
38
45
|
require_paths:
|
39
46
|
- lib
|
40
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
48
|
requirements:
|
43
|
-
- -
|
49
|
+
- - ">="
|
44
50
|
- !ruby/object:Gem::Version
|
45
51
|
version: '0'
|
46
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
53
|
requirements:
|
49
|
-
- -
|
54
|
+
- - ">="
|
50
55
|
- !ruby/object:Gem::Version
|
51
56
|
version: '0'
|
52
57
|
requirements: []
|
53
58
|
rubyforge_project:
|
54
|
-
rubygems_version:
|
59
|
+
rubygems_version: 2.4.5.1
|
55
60
|
signing_key:
|
56
|
-
specification_version:
|
57
|
-
summary: RubyMotion
|
61
|
+
specification_version: 4
|
62
|
+
summary: A RubyMotion gem to help you easily store and retrieve your user's preferences
|
63
|
+
and settings using NSUserDefaults.
|
58
64
|
test_files: []
|
data/.gitignore
DELETED
data/Gemfile
DELETED
data/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2012 Jonathan Silverman, Aaron Hurley
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
# rmsettable.rb
|
2
|
-
# https://github.com/AaronH/RubyMotion-UserSettings
|
3
|
-
|
4
|
-
module RMSettable
|
5
|
-
|
6
|
-
def rm_settable(*args)
|
7
|
-
# Call this in your app_delegate.rb as part of the didFinishLaunchingWithOptions setup.
|
8
|
-
#
|
9
|
-
# The arguments can consist of symbols for various settings you wish to store.
|
10
|
-
#
|
11
|
-
# rm_settable :name, :background_color
|
12
|
-
#
|
13
|
-
#
|
14
|
-
# By default, the keys store and retrieve generic objects. If you wish to specify a
|
15
|
-
# particular type, you may declare that as a hash on the key.
|
16
|
-
#
|
17
|
-
# rm_settable :name, age: {type: :integer}, superstar: {type: :boolean}
|
18
|
-
#
|
19
|
-
# AVAILABLE TYPES :array, :boolean, :data, :dictionary, :double, :float,
|
20
|
-
# :integer, :object, :string_array, :string, :url
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# You can also include a hash of options.
|
24
|
-
#
|
25
|
-
# rm_settable name: {type: :string}, age: options: {autosave: false, default_type: :integer}
|
26
|
-
#
|
27
|
-
# rm_settable options: {:lenient_keys}
|
28
|
-
#
|
29
|
-
# AVAILBLE OPTIONS
|
30
|
-
# :autosave true (default)
|
31
|
-
# By default, settings are synchronized to the device as soon as
|
32
|
-
# it is updated. However, if you are updating a lot of items at once
|
33
|
-
# or would prefer to manually call save on the settings object, set
|
34
|
-
# this to false. Be aware that iOS will still save the settings
|
35
|
-
# periodically without being explicitly called.
|
36
|
-
#
|
37
|
-
# :default_type :object (default)
|
38
|
-
# Items are saved as objects. You many specify the type
|
39
|
-
# when you declare the setting names or override the default
|
40
|
-
# expected for all item.
|
41
|
-
#
|
42
|
-
# :lenient_keys false (default)
|
43
|
-
# If you don't want to declare any or all of the settings you will
|
44
|
-
# be storing, set this to true. Any setting not explicitly declared
|
45
|
-
# will be stored and retrieved as the default setting type.
|
46
|
-
#
|
47
|
-
@rm_settings = RMSettings.new args
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
def applicationDidEnterBackground(application)
|
52
|
-
# make sure we save any unsaved settings when going to the background
|
53
|
-
# if you override this method in the app_delegate
|
54
|
-
# be sure to call super to save any unsaved settings
|
55
|
-
rm_settings.save
|
56
|
-
end
|
57
|
-
|
58
|
-
def applicationWillTerminate(application)
|
59
|
-
# make sure we save any unsaved settings when being terminated
|
60
|
-
# if you override this method in the app_delegate
|
61
|
-
# be sure to call super to save any unsaved settings
|
62
|
-
rm_settings.save
|
63
|
-
end
|
64
|
-
|
65
|
-
def settings
|
66
|
-
# provide access to the RMSettings object to the app_delegate
|
67
|
-
rm_settings
|
68
|
-
end
|
69
|
-
|
70
|
-
def self.included(base)
|
71
|
-
base.class_eval do
|
72
|
-
attr_accessor :rm_settings
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# These subclasses provide easy access to the app_delegate and settings object.
|
78
|
-
# If you wish to call settings directly from your controller or view, be sure
|
79
|
-
# to inherit from these classes
|
80
|
-
class RMView < UIView
|
81
|
-
def settings
|
82
|
-
application.settings
|
83
|
-
end
|
84
|
-
|
85
|
-
def application
|
86
|
-
UIApplication.sharedApplication.delegate
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
class RMViewController < UIViewController
|
91
|
-
def settings
|
92
|
-
application.settings
|
93
|
-
end
|
94
|
-
def application
|
95
|
-
UIApplication.sharedApplication.delegate
|
96
|
-
end
|
97
|
-
end
|
@@ -1,182 +0,0 @@
|
|
1
|
-
# rmsettings.rb
|
2
|
-
# https://github.com/AaronH/RubyMotion-UserSettings
|
3
|
-
|
4
|
-
class RMSettings
|
5
|
-
attr_accessor :settings, :available, :keys, :options
|
6
|
-
|
7
|
-
def initialize(*args)
|
8
|
-
# Initializes the available settings and options
|
9
|
-
# See rmsettable.rb for details on the various options
|
10
|
-
args = args.flatten.compact.uniq
|
11
|
-
@available = {}
|
12
|
-
@settings ||= NSUserDefaults.standardUserDefaults
|
13
|
-
|
14
|
-
user_options = (args.select{|a| a.is_a? Hash}.first || {}).delete(:options) || {}
|
15
|
-
@options = { autosave: true,
|
16
|
-
lenient_keys: false,
|
17
|
-
default_type: :object}.merge(user_options)
|
18
|
-
|
19
|
-
args.flatten.each do |item|
|
20
|
-
if item.is_a?(Symbol)
|
21
|
-
@available[item] = {type: @options[:default_type]}
|
22
|
-
elsif item.is_a?(Hash)
|
23
|
-
item.each do |key, value|
|
24
|
-
@available[key] = value
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
@keys = @available.keys
|
29
|
-
end
|
30
|
-
|
31
|
-
def save
|
32
|
-
# Save all current settings to the device.
|
33
|
-
# Can be called manually but is generally called automatically
|
34
|
-
# after updating a key unless the :autosave option is false.
|
35
|
-
settings.synchronize
|
36
|
-
end
|
37
|
-
|
38
|
-
def autosave
|
39
|
-
# Automatically saves the data unless autosave is false.
|
40
|
-
save if autosave?
|
41
|
-
end
|
42
|
-
|
43
|
-
def autosave?
|
44
|
-
# Check to see if the autosave option is selected
|
45
|
-
options[:autosave]
|
46
|
-
end
|
47
|
-
|
48
|
-
def default_type_for(key)
|
49
|
-
# Determine the appropriate type for reading and writing item
|
50
|
-
((@available[key] || {})[:type] || @options[:default_type])
|
51
|
-
end
|
52
|
-
|
53
|
-
def setting_for?(key)
|
54
|
-
# Call to check boolean status of a particular key.
|
55
|
-
# Generally called dynamically from the method_missing function.
|
56
|
-
#
|
57
|
-
# settings.setting_for? :tutorial_completed
|
58
|
-
#
|
59
|
-
# settings.tutorial_completed?
|
60
|
-
#
|
61
|
-
value = setting_for(key)
|
62
|
-
case default_type_for(key)
|
63
|
-
when :string, :array
|
64
|
-
value.empty?
|
65
|
-
else
|
66
|
-
!!value
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def save_setting(key, value)
|
71
|
-
# Save the contents of value to the key.
|
72
|
-
# Returns the value of the key after setting.
|
73
|
-
#
|
74
|
-
# Generally called dynamically from the method_missing function.
|
75
|
-
#
|
76
|
-
# settings.save_setting :name, 'Karl Pilkington'
|
77
|
-
#
|
78
|
-
# settings.head_shape = 'Orange'
|
79
|
-
#
|
80
|
-
case default_type_for(key)
|
81
|
-
when :boolean
|
82
|
-
settings.setBool value, forKey: key
|
83
|
-
when :double
|
84
|
-
settings.setDouble value, forKey: key
|
85
|
-
when :float
|
86
|
-
settings.setFloat value, forKey: key
|
87
|
-
when :integer
|
88
|
-
settings.setInteger value, forKey: key
|
89
|
-
when :object
|
90
|
-
settings.setObject value, forKey: key
|
91
|
-
when :url
|
92
|
-
settings.setURL value, forKey: key
|
93
|
-
else
|
94
|
-
settings.setObject value, forKey: key
|
95
|
-
end
|
96
|
-
|
97
|
-
autosave
|
98
|
-
|
99
|
-
# return the current value
|
100
|
-
setting_for key
|
101
|
-
end
|
102
|
-
alias :[]= :save_setting
|
103
|
-
|
104
|
-
def setting_for(key)
|
105
|
-
# Read the contents of a given key.
|
106
|
-
#
|
107
|
-
# Generally called dynamically from the method_missing function.
|
108
|
-
#
|
109
|
-
# settings.setting_for :nickname
|
110
|
-
#
|
111
|
-
# settings.nickname
|
112
|
-
#
|
113
|
-
case default_type_for(key)
|
114
|
-
when :array
|
115
|
-
settings.arrayForKey key
|
116
|
-
when :boolean
|
117
|
-
settings.boolForKey key
|
118
|
-
when :data
|
119
|
-
settings.dataForKey key
|
120
|
-
when :dictionary
|
121
|
-
settings.dictionaryForKey key
|
122
|
-
when :double
|
123
|
-
settings.doubleForKey key
|
124
|
-
when :float
|
125
|
-
settings.floatForKey key
|
126
|
-
when :integer
|
127
|
-
settings.integerForKey key
|
128
|
-
when :object
|
129
|
-
settings.objectForKey key
|
130
|
-
when :string_array
|
131
|
-
settings.stringArrayForKey key
|
132
|
-
when :string
|
133
|
-
settings.stringForKey key
|
134
|
-
when :url
|
135
|
-
settings.URLForKey key
|
136
|
-
end
|
137
|
-
end
|
138
|
-
alias :[] :setting_for
|
139
|
-
|
140
|
-
def remove(key)
|
141
|
-
# Resets the key to it's default value and returns that value
|
142
|
-
# Aliased as delete and reset
|
143
|
-
settings.removeObjectForKey key
|
144
|
-
autosave
|
145
|
-
setting_for key
|
146
|
-
end
|
147
|
-
alias :delete :remove
|
148
|
-
alias :reset :remove
|
149
|
-
|
150
|
-
def valid_key?(key)
|
151
|
-
# Checks to see if the method_missing key has been declared
|
152
|
-
# unless that functionality has been turned off in the settings
|
153
|
-
@options[:lenient_keys] or keys.include?(key)
|
154
|
-
end
|
155
|
-
|
156
|
-
def method_missing(method, *args)
|
157
|
-
# Split the method to componenet parts to do our magic.
|
158
|
-
if m = method.to_s.match(/^([^\?\=]+)([\?\=])?$/)
|
159
|
-
base_key = m[1].to_sym
|
160
|
-
method_modifier = m[2]
|
161
|
-
# Check if we want to do something here.
|
162
|
-
if valid_key?(base_key)
|
163
|
-
return case method_modifier
|
164
|
-
when nil
|
165
|
-
# Call the reader
|
166
|
-
setting_for(base_key)
|
167
|
-
when '='
|
168
|
-
# Call the writer
|
169
|
-
save_setting(base_key, [*args].flatten.first)
|
170
|
-
when '?'
|
171
|
-
# Call the boolean check
|
172
|
-
setting_for?(base_key)
|
173
|
-
else
|
174
|
-
# Nothing to do, so let's fail
|
175
|
-
super
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
179
|
-
super
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
data/motion-settings.gemspec
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/motion-settings/version', __FILE__)
|
3
|
-
|
4
|
-
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Jonathan Silverman", "Aaron Hurley"]
|
6
|
-
gem.email = ["jsilver@mdx.la", "aaron@showtimefu.com"]
|
7
|
-
gem.description = %q{A convenience wrapper to allow RubyMotion apps easy access to reading, writing, and persisting values via NSUserDefaults.}
|
8
|
-
gem.summary = %q{RubyMotion Settings Library}
|
9
|
-
gem.homepage = "https://github.com/jsilverMDX/RubyMotion-UserSettings"
|
10
|
-
|
11
|
-
gem.files = `git ls-files`.split($\)
|
12
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
-
gem.name = "motion-settings"
|
15
|
-
gem.require_paths = ["lib"]
|
16
|
-
gem.version = Motion::Settings::VERSION
|
17
|
-
end
|