motion-encodable 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -3
- data/lib/motion/encodable.rb +3 -4
- data/motion-encodable.gemspec +3 -3
- data/spec/motion/encodable_spec.rb +7 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58b1172e2a0493511d454cd35d20862f9a0e81eb
|
4
|
+
data.tar.gz: 7b33fab8d2a4ee49acaaf3b1fb2448776e333451
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4db81afa6b39e19f75b2c1e0fe589eae00a0f2011c6fe1c01f45f61fcabf77ad554cb4bf09f563c6d0edd2edf876a4084ce7180bda02a667a74090fcf3318f8f
|
7
|
+
data.tar.gz: 9fdb5a1fb37ab2982c0fa37d7b0a96e16a088b6f580e7387c3057dc8d0be76af241eb81ada18a9bcbcc8ad70a67736cb88b6ba269c4961834842d39f14a8fea8
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
[](https://gemnasium.com/satococoa/motion-encodable)
|
6
6
|
[](https://codeclimate.com/github/satococoa/motion-encodable)
|
7
7
|
|
8
|
-
Implement NSCoding protocol methods with ease
|
8
|
+
Implement NSCoding protocol methods with ease for RubyMotion.
|
9
9
|
|
10
10
|
## Installation
|
11
11
|
|
@@ -42,8 +42,17 @@ user_defaults = NSUserDefaults.standardUserDefaults
|
|
42
42
|
user_defaults[:entry] = entry.to_data
|
43
43
|
|
44
44
|
loaded_entry = Entry.load(user_defaults[:entry])
|
45
|
-
loaded_entry.title # => "foo"
|
46
|
-
loaded_entry.body # => "bar"
|
45
|
+
loaded_entry.instance_variable_get('@title') # => "foo"
|
46
|
+
loaded_entry.instance_variable_get('@body') # => "bar"
|
47
|
+
|
48
|
+
# save to file
|
49
|
+
dir_path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]
|
50
|
+
file_path = dir_path + '/entry.dat'
|
51
|
+
entry.save_to_file(file_path)
|
52
|
+
|
53
|
+
loaded_entry = Entry.load(NSData.dataWithContentsOfFile(file_path))
|
54
|
+
loaded_entry.instance_variable_get('@title') # => "foo"
|
55
|
+
loaded_entry.instance_variable_get('@body') # => "bar"
|
47
56
|
```
|
48
57
|
|
49
58
|
## Contributing
|
data/lib/motion/encodable.rb
CHANGED
@@ -6,10 +6,9 @@ class Motion
|
|
6
6
|
|
7
7
|
module ClassMethods
|
8
8
|
def properties(*props)
|
9
|
+
@properties = []
|
9
10
|
props.each {|prop|
|
10
|
-
@properties ||= []
|
11
11
|
@properties << prop
|
12
|
-
attr_accessor prop
|
13
12
|
}
|
14
13
|
end
|
15
14
|
|
@@ -35,14 +34,14 @@ class Motion
|
|
35
34
|
self.init
|
36
35
|
properties.each {|prop|
|
37
36
|
v = decoder.decodeObjectForKey(prop.to_s)
|
38
|
-
self.
|
37
|
+
self.instance_variable_set(:"@#{prop}", v) if v
|
39
38
|
}
|
40
39
|
self
|
41
40
|
end
|
42
41
|
|
43
42
|
def encodeWithCoder(encoder)
|
44
43
|
properties.each {|prop|
|
45
|
-
encoder.encodeObject(self.
|
44
|
+
encoder.encodeObject(self.instance_variable_get(:"@#{prop}"), forKey: prop.to_s)
|
46
45
|
}
|
47
46
|
end
|
48
47
|
# // NSCoding protocol
|
data/motion-encodable.gemspec
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
VERSION = "0.0.
|
2
|
+
VERSION = "0.0.3"
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "motion-encodable"
|
6
6
|
spec.version = VERSION
|
7
7
|
spec.authors = ["Satoshi Ebisawa"]
|
8
8
|
spec.email = ["e.satoshi@gmail.com"]
|
9
|
-
spec.description = %q{Implement NSCoding protocol methods with ease}
|
10
|
-
spec.summary = %q{Implement NSCoding protocol methods with ease}
|
9
|
+
spec.description = %q{Implement NSCoding protocol methods with ease for RubyMotion.}
|
10
|
+
spec.summary = %q{Implement NSCoding protocol methods with ease for RubyMotion.}
|
11
11
|
spec.homepage = "https://github.com/satococoa/motion-encodable"
|
12
12
|
spec.license = "MIT"
|
13
13
|
|
@@ -1,8 +1,9 @@
|
|
1
1
|
class Entry
|
2
2
|
include Motion::Encodable
|
3
|
-
properties :title
|
3
|
+
properties :title, :body
|
4
4
|
def initialize(params={})
|
5
5
|
@title = params[:title]
|
6
|
+
@body = params[:body]
|
6
7
|
end
|
7
8
|
end
|
8
9
|
|
@@ -10,6 +11,7 @@ describe Motion::Encodable do
|
|
10
11
|
before do
|
11
12
|
@params = {
|
12
13
|
title: 'bar',
|
14
|
+
body: 'baz'
|
13
15
|
}
|
14
16
|
end
|
15
17
|
|
@@ -38,14 +40,16 @@ describe Motion::Encodable do
|
|
38
40
|
it 'should be able to load as data' do
|
39
41
|
entry_as_data = @entry.to_data
|
40
42
|
loaded_entry = Entry.load(entry_as_data)
|
41
|
-
loaded_entry.title.should == @params[:title]
|
43
|
+
loaded_entry.instance_variable_get(:'@title').should == @params[:title]
|
44
|
+
loaded_entry.instance_variable_get(:'@body').should == @params[:body]
|
42
45
|
end
|
43
46
|
|
44
47
|
it 'should be able to save into file' do
|
45
48
|
@entry.save_to_file(@file_path)
|
46
49
|
entry_as_data = NSData.dataWithContentsOfFile(@file_path)
|
47
50
|
loaded_entry = Entry.load(entry_as_data)
|
48
|
-
loaded_entry.title.should == @params[:title]
|
51
|
+
loaded_entry.instance_variable_get('@title').should == @params[:title]
|
52
|
+
loaded_entry.instance_variable_get('@body').should == @params[:body]
|
49
53
|
end
|
50
54
|
end
|
51
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-encodable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Satoshi Ebisawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -38,7 +38,7 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
|
-
description: Implement NSCoding protocol methods with ease
|
41
|
+
description: Implement NSCoding protocol methods with ease for RubyMotion.
|
42
42
|
email:
|
43
43
|
- e.satoshi@gmail.com
|
44
44
|
executables: []
|
@@ -80,7 +80,7 @@ rubyforge_project:
|
|
80
80
|
rubygems_version: 2.0.3
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
|
-
summary: Implement NSCoding protocol methods with ease
|
83
|
+
summary: Implement NSCoding protocol methods with ease for RubyMotion.
|
84
84
|
test_files:
|
85
85
|
- spec/motion/encodable_spec.rb
|
86
86
|
has_rdoc:
|