motion-persistable 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.repl_history +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +74 -0
- data/Rakefile +14 -0
- data/app/app_delegate.rb +5 -0
- data/app/user.rb +30 -0
- data/lib/motion/persistable/version.rb +5 -0
- data/lib/motion/persistable.rb +49 -0
- data/lib/motion-persistable.rb +15 -0
- data/motion-persistable.gemspec +24 -0
- data/spec/user_spec.rb +79 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9dd19726462662517ea8c12e098630b8918796cf
|
4
|
+
data.tar.gz: 1d7e6d702c4db54d666043026b2cd621b568adea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b4ead8d44ef350bfc4431b05733eb9358ce69896055b42c606d04cbfd3235f4630e53edb42e2964a2892915769faa3bd2ee56acaa34208de29c2b3e5ab5b8ae
|
7
|
+
data.tar.gz: 02e31160b124ae2c2fd90694254cc61a7d3ce642ed1aede1ced365b968b94b0007ca919fe3df88fe83c3f4d260d301ebb5e2a81019cc93d523c969c7241fc39f
|
data/.gitignore
ADDED
data/.repl_history
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
User
|
2
|
+
exit
|
3
|
+
User.new.age
|
4
|
+
User.new.email
|
5
|
+
User.new('theore').age
|
6
|
+
User.new('theore').age
|
7
|
+
domainName = NSBundle.mainBundle.bundleIdentifier
|
8
|
+
NSUserDefaults.standardUserDefaults.removePersistentDomainForName(domainName)
|
9
|
+
User.new('theore').age
|
10
|
+
User.new('theore').age = 14
|
11
|
+
User.new('theore').age
|
12
|
+
domainName = NSBundle.mainBundle.bundleIdentifier
|
13
|
+
NSUserDefaults.standardUserDefaults.removePersistentDomainForName(domainName)
|
14
|
+
User.new('theore').age
|
15
|
+
exit
|
16
|
+
User.new("Bodacious").last_signed_in = Time.now
|
17
|
+
User.new("Bodacious").last_sign_in = Time.now
|
18
|
+
STDOUT
|
19
|
+
STDOUT.read
|
20
|
+
exit
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Bodacious
|
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/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Motion::Persistable
|
2
|
+
|
3
|
+
## Persistable attributes for Rubymotion classes
|
4
|
+
|
5
|
+
A nice wrapper around Bubble-wrap's App::Persistence module that adds class macros for attributes that are persistable
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'motion-persistable'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundles
|
16
|
+
|
17
|
+
Add this line to your application's Rakefile:
|
18
|
+
|
19
|
+
Bundler.require # this should already be there
|
20
|
+
require 'motion-persistable'
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install motion-persistable
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Include the module Motion::Persistable in any class that you want persistable attributes
|
29
|
+
|
30
|
+
### Persistable Instance Methods
|
31
|
+
|
32
|
+
class User
|
33
|
+
|
34
|
+
include Motion::Persistable
|
35
|
+
|
36
|
+
# Define this in your model to use your own key, otherise it will try and call
|
37
|
+
# name() on the instance by default
|
38
|
+
def persistence_key
|
39
|
+
"User"
|
40
|
+
end
|
41
|
+
|
42
|
+
# This will persist the user's email under the key: "User.bodacious.email" (where the
|
43
|
+
# user's username was bodacious)
|
44
|
+
attr_persisted :email, '', :username
|
45
|
+
|
46
|
+
# This will set an attribute called age, with a default value of 16.
|
47
|
+
# When a new value is set, the block is called, in this case it's recorded on TestFlight
|
48
|
+
attr_persisted :age, 16, :username do |value|
|
49
|
+
testflight_checkpoint("Set new age value", age: value)
|
50
|
+
end
|
51
|
+
|
52
|
+
class << self
|
53
|
+
include Motion::Persistable # for class methods
|
54
|
+
|
55
|
+
# This will set a class attribute User.count with a default value of 0
|
56
|
+
attr_persisted :count, 0
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
## Considerations
|
63
|
+
|
64
|
+
The obvious drawback with this current approach is that instances require unique keys.
|
65
|
+
For the project this was designed for, this wasn't an issue but if your instances don't
|
66
|
+
already have some sort of unique identifier then this gem might not be best for you.
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
1. Fork it
|
71
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
72
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
73
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
74
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
|
4
|
+
$:.unshift('/Library/RubyMotion/lib')
|
5
|
+
require 'motion/project/template/ios'
|
6
|
+
require 'bundler'
|
7
|
+
|
8
|
+
Bundler.require
|
9
|
+
require 'motion/persistable'
|
10
|
+
|
11
|
+
Motion::Project::App.setup do |app|
|
12
|
+
# Use `rake config' to see complete project settings.
|
13
|
+
app.name = 'Motion-Persistable'
|
14
|
+
end
|
data/app/app_delegate.rb
ADDED
data/app/user.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
class User
|
2
|
+
|
3
|
+
attr_accessor :username
|
4
|
+
|
5
|
+
include Motion::Persistable
|
6
|
+
|
7
|
+
attr_persisted :email, ''
|
8
|
+
|
9
|
+
attr_persisted :age, 16
|
10
|
+
|
11
|
+
attr_persisted :location
|
12
|
+
|
13
|
+
attr_persisted :last_sign_in, nil do |value|
|
14
|
+
App::Persistence['last_sign_in'] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
include Motion::Persistable
|
19
|
+
attr_persisted :last_signed_in_user
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(username)
|
23
|
+
self.username = username
|
24
|
+
end
|
25
|
+
|
26
|
+
def name
|
27
|
+
username
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Motion
|
2
|
+
module Persistable
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
def persistence_key
|
9
|
+
if respond_to?(:key)
|
10
|
+
key
|
11
|
+
else
|
12
|
+
name
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
|
18
|
+
def attr_persisted(method_name, default_value = nil, key_suffix = nil, &block)
|
19
|
+
callback = block if block_given?
|
20
|
+
|
21
|
+
instance_eval do
|
22
|
+
|
23
|
+
define_method method_name do
|
24
|
+
if App::Persistence[send("_#{method_name}_key")].nil? and default_value
|
25
|
+
App::Persistence[send("_#{method_name}_key")] = default_value
|
26
|
+
end
|
27
|
+
App::Persistence[send("_#{method_name}_key")]
|
28
|
+
end
|
29
|
+
|
30
|
+
define_method "#{method_name}=" do |value|
|
31
|
+
App::Persistence[send("_#{method_name}_key")] = value
|
32
|
+
callback.call(value) if callback
|
33
|
+
App::Persistence[send("_#{method_name}_key")]
|
34
|
+
end
|
35
|
+
|
36
|
+
define_method "_#{method_name}_key" do
|
37
|
+
key_suffix = send(key_suffix) if key_suffix.is_a?(Symbol)
|
38
|
+
[persistence_key, key_suffix, method_name].compact.join('.')
|
39
|
+
end
|
40
|
+
|
41
|
+
private "_#{method_name}_key"
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
require 'bubble-wrap/core'
|
6
|
+
|
7
|
+
require 'motion/persistable/version'
|
8
|
+
|
9
|
+
Motion::Project::App.setup do |app|
|
10
|
+
path_string = File.join(File.dirname(__FILE__), 'motion/persistable.rb')
|
11
|
+
Dir.glob(path_string).each do |file|
|
12
|
+
app.files.unshift(file)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'motion/persistable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "motion-persistable"
|
8
|
+
spec.version = Motion::Persistable::VERSION
|
9
|
+
spec.authors = ["Bodacious"]
|
10
|
+
spec.email = ["gavin@katanacode.com"]
|
11
|
+
spec.description = %q{Persistable attributes for Rubymotion classes}
|
12
|
+
spec.summary = %q{A nice wrapper around Bubble-wrap's App::Persistence module that adds class macros for attributes that are persistable}
|
13
|
+
spec.homepage = "http://github.com/KatanaCode/motion-persistable"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency 'bubble-wrap'
|
21
|
+
spec.add_development_dependency 'motion-stump'
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
data/spec/user_spec.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
describe "User" do
|
2
|
+
before do
|
3
|
+
@user = User.new('bodacious')
|
4
|
+
end
|
5
|
+
|
6
|
+
after do
|
7
|
+
# Clear out the cache
|
8
|
+
domainName = NSBundle.mainBundle.bundleIdentifier
|
9
|
+
NSUserDefaults.standardUserDefaults.removePersistentDomainForName(domainName)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "email" do
|
13
|
+
|
14
|
+
it "is persisted between instances" do
|
15
|
+
@user.email = "bodacious@katanacode.com"
|
16
|
+
@user = User.new("bodacious")
|
17
|
+
@user.email.should == "bodacious@katanacode.com"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "defaults to an empty string" do
|
21
|
+
@user = User.new("other-user")
|
22
|
+
@user.email.should == ""
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "age" do
|
28
|
+
|
29
|
+
it "defaults to 16" do
|
30
|
+
@user = User.new("other-user")
|
31
|
+
@user.age.should == 16
|
32
|
+
end
|
33
|
+
|
34
|
+
it "is persisted between instances" do
|
35
|
+
@user.age = 28
|
36
|
+
@user = User.new("bodacious")
|
37
|
+
@user.age.should == 28
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "location" do
|
43
|
+
|
44
|
+
it "defaults to nil" do
|
45
|
+
@user = User.new("other-user")
|
46
|
+
@user.location.should == nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it "is persisted between instances" do
|
50
|
+
@user.location = "Edinburgh"
|
51
|
+
@user = User.new("bodacious")
|
52
|
+
@user.location.should == "Edinburgh"
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "last_sign_in" do
|
58
|
+
|
59
|
+
it "defaults to nil" do
|
60
|
+
@user = User.new("other-user")
|
61
|
+
@user.last_sign_in.should == nil
|
62
|
+
end
|
63
|
+
|
64
|
+
it "is persisted between instances" do
|
65
|
+
@user.last_sign_in = Time.now
|
66
|
+
@user = User.new("bodacious")
|
67
|
+
@user.last_sign_in.should != nil
|
68
|
+
end
|
69
|
+
|
70
|
+
it "calls the callback block when set" do
|
71
|
+
User.last_signed_in_user = nil
|
72
|
+
time = Time.now
|
73
|
+
@user.last_sign_in = time
|
74
|
+
App::Persistence['last_sign_in'].should == time
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-persistable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bodacious
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bubble-wrap
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: motion-stump
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Persistable attributes for Rubymotion classes
|
70
|
+
email:
|
71
|
+
- gavin@katanacode.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .repl_history
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- app/app_delegate.rb
|
83
|
+
- app/user.rb
|
84
|
+
- lib/motion-persistable.rb
|
85
|
+
- lib/motion/persistable.rb
|
86
|
+
- lib/motion/persistable/version.rb
|
87
|
+
- motion-persistable.gemspec
|
88
|
+
- spec/user_spec.rb
|
89
|
+
homepage: http://github.com/KatanaCode/motion-persistable
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.1.11
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: A nice wrapper around Bubble-wrap's App::Persistence module that adds class
|
113
|
+
macros for attributes that are persistable
|
114
|
+
test_files:
|
115
|
+
- spec/user_spec.rb
|