api-model 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -1
- data/api-model.gemspec +2 -1
- data/lib/api-model.rb +1 -0
- data/lib/api_model/instance_methods.rb +7 -0
- data/spec/api-model/api_model_spec.rb +21 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d62e3abae3a9c3844eeaa606a37263f57d096057
|
4
|
+
data.tar.gz: 1cc5a013afbc09fb71f12cded4e9ed6aeb8f5be6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebd2bc0b6ff25732cfac277f91888c908073970bce8eec68be7c59e7b3edc20ccb3abba66e8bc1deb8b0a7c398c0f84f704bf2c6e0e889be3df991828a9d58e2
|
7
|
+
data.tar.gz: 3b2df71ea9b2fddc4c220f4c4281c62bd2c45c8ac10fc2f22d92e96972287120a27cd078c8cd79e202c9820c32400de143767d6b398ff8f643fed90a55d75a1b
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
api-model (1.1.
|
4
|
+
api-model (1.1.2)
|
5
5
|
activemodel (~> 4.0)
|
6
6
|
activesupport (~> 4.0)
|
7
|
+
hash-pipe (~> 0.0)
|
7
8
|
hashie (~> 2.0)
|
8
9
|
typhoeus (~> 0.6)
|
9
10
|
|
@@ -30,6 +31,8 @@ GEM
|
|
30
31
|
ffi (>= 1.3.0)
|
31
32
|
mime-types (~> 1.18)
|
32
33
|
ffi (1.9.3)
|
34
|
+
hash-pipe (0.0.1)
|
35
|
+
activesupport (~> 4.0)
|
33
36
|
hashie (2.0.5)
|
34
37
|
i18n (0.6.9)
|
35
38
|
method_source (0.8.2)
|
data/api-model.gemspec
CHANGED
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "api-model"
|
5
|
-
s.version = "1.1.
|
5
|
+
s.version = "1.1.2"
|
6
6
|
s.authors = ["Damien Timewell"]
|
7
7
|
s.email = ["mail@damientimewell.com"]
|
8
8
|
s.licenses = ['MIT']
|
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.add_dependency 'activemodel', '~> 4.0'
|
15
15
|
s.add_dependency 'typhoeus', '~> 0.6'
|
16
16
|
s.add_dependency 'hashie', '~> 2.0'
|
17
|
+
s.add_dependency 'hash-pipe', '~> 0.0'
|
17
18
|
|
18
19
|
s.add_development_dependency "rspec", '~> 2.14'
|
19
20
|
s.add_development_dependency "pry", '~> 0.9'
|
data/lib/api-model.rb
CHANGED
@@ -70,5 +70,12 @@ module ApiModel
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
+
# Returns all the defined properties in a hash without the :persisted property which was added automatically.
|
74
|
+
#
|
75
|
+
# This is useful for when you need to pass the entire object back to an API, or if you want to serialize the object.
|
76
|
+
def properties_hash
|
77
|
+
self.to_hash.only(*self.class.properties.to_a).except(:persisted).with_indifferent_access
|
78
|
+
end
|
79
|
+
|
73
80
|
end
|
74
81
|
end
|
@@ -287,4 +287,25 @@ describe ApiModel do
|
|
287
287
|
end
|
288
288
|
end
|
289
289
|
|
290
|
+
describe "properties_hash" do
|
291
|
+
let(:blog_post) { BlogPost.new title: "Foo", name: "Bar", something_else: "Baz" }
|
292
|
+
|
293
|
+
it 'should return a hash' do
|
294
|
+
blog_post.properties_hash.should be_a(Hash)
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'should include attributes which are defined as properties' do
|
298
|
+
blog_post.properties_hash.should have_key(:title)
|
299
|
+
blog_post.properties_hash.should have_key(:name)
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'should not include attributes which are not defined as properties' do
|
303
|
+
blog_post.properties_hash.should_not have_key(:something_else)
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'should not include the :persisted property, even though it is defined' do
|
307
|
+
blog_post.properties_hash.should_not have_key(:persisted)
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
290
311
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Timewell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hash-pipe
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rspec
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|