motion-encodable 0.0.1 → 0.0.2
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/.gitignore +1 -0
- data/README.md +2 -1
- data/lib/motion/encodable.rb +4 -0
- data/motion-encodable.gemspec +1 -1
- data/spec/motion/encodable_spec.rb +20 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b280c2117cce5bcc4ff553bb33cab8cf468d6a1
|
4
|
+
data.tar.gz: fd9690c242ece1c1453a8a9d52a2241a2be139cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d81ec337fde70ab58d13169b7aaab1075762b9f59cddc427e2806071e7ae1bfde152d7a576897b14e527fc14b0a2d162a16824b078ada5eadccec7acdeffdfb3
|
7
|
+
data.tar.gz: a1c776ce78741097a019fcde670911409656cce8021a0c33a56d710ebd1d82419b7d0af8cfe4f5a6ad1cf603a3434ec1a8615395f3d05788eedf2f4417aff7e4
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# motion-encodable
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/motion-encodable)
|
3
4
|
[](https://travis-ci.org/satococoa/motion-encodable)
|
4
5
|
[](https://gemnasium.com/satococoa/motion-encodable)
|
5
6
|
[](https://codeclimate.com/github/satococoa/motion-encodable)
|
@@ -24,7 +25,7 @@ Or install it yourself as:
|
|
24
25
|
|
25
26
|
```
|
26
27
|
class Entry
|
27
|
-
include Encodable
|
28
|
+
include Motion::Encodable
|
28
29
|
properties :title, :body
|
29
30
|
end
|
30
31
|
```
|
data/lib/motion/encodable.rb
CHANGED
data/motion-encodable.gemspec
CHANGED
@@ -16,6 +16,18 @@ describe Motion::Encodable do
|
|
16
16
|
describe 'NSCoder protocol' do
|
17
17
|
before do
|
18
18
|
@entry = Entry.new(@params)
|
19
|
+
dir_path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true)[0]
|
20
|
+
@file_path = dir_path + '/entry.dat'
|
21
|
+
end
|
22
|
+
|
23
|
+
after do
|
24
|
+
# remove saved file
|
25
|
+
file_manager = NSFileManager.defaultManager
|
26
|
+
if file_manager.fileExistsAtPath(@file_path)
|
27
|
+
error = Pointer.new(:object)
|
28
|
+
file_manager.removeItemAtPath(@file_path, error: error)
|
29
|
+
raise error[0] if error[0]
|
30
|
+
end
|
19
31
|
end
|
20
32
|
|
21
33
|
it 'should responds to required methods' do
|
@@ -23,10 +35,17 @@ describe Motion::Encodable do
|
|
23
35
|
@entry.respond_to?(:'encodeWithCoder:').should == true
|
24
36
|
end
|
25
37
|
|
26
|
-
it 'should be able to load' do
|
38
|
+
it 'should be able to load as data' do
|
27
39
|
entry_as_data = @entry.to_data
|
28
40
|
loaded_entry = Entry.load(entry_as_data)
|
29
41
|
loaded_entry.title.should == @params[:title]
|
30
42
|
end
|
43
|
+
|
44
|
+
it 'should be able to save into file' do
|
45
|
+
@entry.save_to_file(@file_path)
|
46
|
+
entry_as_data = NSData.dataWithContentsOfFile(@file_path)
|
47
|
+
loaded_entry = Entry.load(entry_as_data)
|
48
|
+
loaded_entry.title.should == @params[:title]
|
49
|
+
end
|
31
50
|
end
|
32
51
|
end
|