motion-encodable 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 195f164b3633c8ad4a79e14493d5a7065be2a304
4
+ data.tar.gz: 37f4ec00e489977d48d3499ec0f2e21f52f4e73c
5
+ SHA512:
6
+ metadata.gz: 9dcb3e05621b325cc7e94a1cf24b6ba7e8e650ab4af93dddf1307babbe683cae869748dca732b8bde0dfde067bb932539ee9020f883efd006eab33fee534387c
7
+ data.tar.gz: 2f099f88a21d3bc297d750c29af95e5722efea3afd0187a8ea9226430fa7dd948b4660c1dd3205f2c2dbd349413161db66032f5345a82c1dd7d55d20455f2e85
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ .repl_history
2
+ build
3
+ tags
4
+ app/pixate_code.rb
5
+ resources/*.nib
6
+ resources/*.momd
7
+ resources/*.storyboardc
8
+ .DS_Store
9
+ nbproject
10
+ .redcar
11
+ #*#
12
+ *~
13
+ *.sw[po]
14
+ .eprj
15
+ .sass-cache
16
+ .idea
17
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1 @@
1
+ language: objective-c
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_paginator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Satoshi Ebisawa
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,54 @@
1
+ # motion-encodable
2
+
3
+ [![Build Status](https://travis-ci.org/satococoa/motion-encodable.png?branch=master)](https://travis-ci.org/satococoa/motion-encodable)
4
+ [![Dependency Status](https://gemnasium.com/satococoa/motion-encodable.png)](https://gemnasium.com/satococoa/motion-encodable)
5
+ [![Code Climate](https://codeclimate.com/github/satococoa/motion-encodable.png)](https://codeclimate.com/github/satococoa/motion-encodable)
6
+
7
+ Implement NSCoding protocol methods with ease
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'motion-encodable'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install motion-encodable
22
+
23
+ ## Usage
24
+
25
+ ```
26
+ class Entry
27
+ include Encodable
28
+ properties :title, :body
29
+ end
30
+ ```
31
+
32
+ Now, you can serialize and deserialize your object using NSCoding protocol.
33
+
34
+ ```
35
+ entry = Entry.new
36
+ entry.title = 'foo'
37
+ entry.body = 'bar'
38
+
39
+ # save to NSUserDefaults
40
+ user_defaults = NSUserDefaults.standardUserDefaults
41
+ user_defaults[:entry] = entry.to_data
42
+
43
+ loaded_entry = Entry.load(user_defaults[:entry])
44
+ loaded_entry.title # => "foo"
45
+ loaded_entry.body # => "bar"
46
+ ```
47
+
48
+ ## Contributing
49
+
50
+ 1. Fork it
51
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
52
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
53
+ 4. Push to the branch (`git push origin my-new-feature`)
54
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+ $:.unshift("/Library/RubyMotion/lib")
3
+ require 'motion/project/template/ios'
4
+ require './lib/motion-encodable'
5
+
6
+ require "bundler/gem_tasks"
7
+
8
+ Motion::Project::App.setup do |app|
9
+ # Use `rake config' to see complete project settings.
10
+ app.name = 'motion-encodable'
11
+ end
@@ -0,0 +1,5 @@
1
+ class AppDelegate
2
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
3
+ true
4
+ end
5
+ end
@@ -0,0 +1,8 @@
1
+ unless defined?(Motion::Project::Config)
2
+ raise "This file must be required within a RubyMotion project Rakefile."
3
+ end
4
+
5
+ lib_dir_path = File.dirname(File.expand_path(__FILE__))
6
+ Motion::Project::App.setup do |app|
7
+ app.files.unshift(Dir.glob(File.join(lib_dir_path, "motion/**/*.rb")))
8
+ end
@@ -0,0 +1,47 @@
1
+ class Motion
2
+ module Encodable
3
+ def self.included(base)
4
+ base.extend ClassMethods
5
+ end
6
+
7
+ module ClassMethods
8
+ def properties(*props)
9
+ props.each {|prop|
10
+ @properties ||= []
11
+ @properties << prop
12
+ attr_accessor prop
13
+ }
14
+ end
15
+
16
+ def load(data)
17
+ NSKeyedUnarchiver.unarchiveObjectWithData(data)
18
+ end
19
+ end
20
+
21
+ def properties
22
+ self.class.instance_variable_get(:'@properties')
23
+ end
24
+
25
+ def to_data
26
+ NSKeyedArchiver.archivedDataWithRootObject(self)
27
+ end
28
+
29
+ # NSCoding protocol
30
+ def initWithCoder(decoder)
31
+ self.init
32
+ properties.each {|prop|
33
+ v = decoder.decodeObjectForKey(prop.to_s)
34
+ self.send("#{prop}=", v) if v
35
+ }
36
+ self
37
+ end
38
+
39
+ def encodeWithCoder(encoder)
40
+ properties.each {|prop|
41
+ encoder.encodeObject(self.send(prop), forKey: prop.to_s)
42
+ }
43
+ end
44
+ # // NSCoding protocol
45
+ end
46
+ end
47
+
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ VERSION = "0.0.1"
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "motion-encodable"
6
+ spec.version = VERSION
7
+ spec.authors = ["Satoshi Ebisawa"]
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}
11
+ spec.homepage = "https://github.com/satococoa/motion-encodable"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "rake"
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ end
Binary file
@@ -0,0 +1,32 @@
1
+ class Entry
2
+ include Motion::Encodable
3
+ properties :title
4
+ def initialize(params={})
5
+ @title = params[:title]
6
+ end
7
+ end
8
+
9
+ describe Motion::Encodable do
10
+ before do
11
+ @params = {
12
+ title: 'bar',
13
+ }
14
+ end
15
+
16
+ describe 'NSCoder protocol' do
17
+ before do
18
+ @entry = Entry.new(@params)
19
+ end
20
+
21
+ it 'should responds to required methods' do
22
+ @entry.respond_to?(:'initWithCoder:').should == true
23
+ @entry.respond_to?(:'encodeWithCoder:').should == true
24
+ end
25
+
26
+ it 'should be able to load' do
27
+ entry_as_data = @entry.to_data
28
+ loaded_entry = Entry.load(entry_as_data)
29
+ loaded_entry.title.should == @params[:title]
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: motion-encodable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Satoshi Ebisawa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ description: Implement NSCoding protocol methods with ease
42
+ email:
43
+ - e.satoshi@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .travis.yml
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - app/app_delegate.rb
55
+ - lib/motion-encodable.rb
56
+ - lib/motion/encodable.rb
57
+ - motion-encodable.gemspec
58
+ - resources/Default-568h@2x.png
59
+ - spec/motion/encodable_spec.rb
60
+ homepage: https://github.com/satococoa/motion-encodable
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.0.3
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Implement NSCoding protocol methods with ease
84
+ test_files:
85
+ - spec/motion/encodable_spec.rb
86
+ has_rdoc: