otis 0.0.6 → 0.0.7
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 +8 -8
- data/lib/otis.rb +1 -0
- data/lib/otis/error.rb +4 -0
- data/lib/otis/otis_object.rb +5 -4
- data/lib/otis/version.rb +1 -1
- data/otis.gemspec +1 -1
- data/spec/lib/otis/otis_object_spec.rb +51 -32
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGJhMGRmNjE3ZDcyZmRjYmFmZTNlOGJlZmZkYTJmMDZiNDZkMjUzMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzJiOTU1ZjhlYTkyNjAzNmQ3NTcyNDZkMTRmNzQ4OWM4ZWU0MzNjMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjlkZDJlMTIyMzU3ZGE4MTMxM2U3MzdkYTUyNjI2MTdhZWMwZDZiMjE0MWZl
|
10
|
+
Mjc4MTY4ZDBlMGM0M2VjM2RmNjJkMDQxZWZiOTM2ZDZkZDViNDY5NzdhMDZj
|
11
|
+
OGE0NTYwYmQ2M2UwZmE2ZGYzMTFkMGM1ZDZkYmIzOWQ5YTU0NWY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTM1YzNkMjA4Njg5NGZjMjEyNGEyNWEwZmU1NzAyMmYzNWRkZDg5ODJjZTIy
|
14
|
+
NzAwMzllYmI2NGM4ZmYyOWMzMDIzMThlMDNlNTFjY2VlNTA3NDQzYmZjZWIx
|
15
|
+
OTRlMTM3NTNiMDljOGM1ODQ0ODk4YmFhYzE0MzUyZmRiYTBkN2E=
|
data/lib/otis.rb
CHANGED
data/lib/otis/error.rb
ADDED
data/lib/otis/otis_object.rb
CHANGED
@@ -5,9 +5,10 @@ module Otis
|
|
5
5
|
base.extend(ClassExtension)
|
6
6
|
end
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@response
|
10
|
-
|
8
|
+
def initialize(attributes = {})
|
9
|
+
raise UnexpectedContentError.new("Array received when a hash was expected by class #{self.class}: \n#{@response}") if attributes.is_a?(Array)
|
10
|
+
@response = attributes
|
11
|
+
@response.each_pair do |k, v|
|
11
12
|
m = underscore(k.to_s)
|
12
13
|
self.send("#{m}=", v ) if self.respond_to?("#{m}=")
|
13
14
|
end
|
@@ -28,7 +29,7 @@ module Otis
|
|
28
29
|
def collection(opts ={})
|
29
30
|
collection = opts[:as].to_s
|
30
31
|
klass = opts[:of]
|
31
|
-
class_eval %(def #{collection}; @#{collection} ||=
|
32
|
+
class_eval %( def #{collection}; @#{collection} ||= [@response[:#{collection}]].compact.flatten.map{|c| #{klass}.new(c)}; end )
|
32
33
|
end
|
33
34
|
|
34
35
|
#
|
data/lib/otis/version.rb
CHANGED
data/otis.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "debugger"
|
24
24
|
spec.add_development_dependency "rspec"
|
25
25
|
|
26
|
-
spec.add_dependency 'savon', '~> 2.
|
26
|
+
spec.add_dependency 'savon', '~> 2.3'
|
27
27
|
spec.add_dependency 'faraday'
|
28
28
|
spec.add_dependency 'virtus'
|
29
29
|
end
|
@@ -1,48 +1,67 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
module Otis
|
4
|
+
describe Object do
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
describe 'initializer' do
|
7
|
+
class TestClass; include Object; end
|
8
|
+
context 'with an unexpected content' do
|
9
|
+
it 'raises an exception' do
|
10
|
+
expect { TestClass.new([])}.to raise_error(UnexpectedContentError)
|
11
|
+
end
|
12
|
+
end
|
8
13
|
end
|
9
14
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
15
|
+
describe 'collection' do
|
16
|
+
class Thing < Model
|
17
|
+
attribute :a
|
18
|
+
end
|
14
19
|
|
15
|
-
|
20
|
+
class TestClass
|
21
|
+
include Object
|
22
|
+
collection of: Thing, as: :things
|
23
|
+
end
|
16
24
|
|
17
|
-
|
18
|
-
expect(klass).to respond_to(:things)
|
19
|
-
end
|
25
|
+
let(:klass) { TestClass.new }
|
20
26
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
expect(klass.things.count).to eq(2)
|
25
|
-
end
|
27
|
+
it 'creates the get' do
|
28
|
+
expect(klass).to respond_to(:things)
|
29
|
+
end
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
it 'holds a collection' do
|
32
|
+
klass = TestClass.new
|
33
|
+
klass.things << Thing.new
|
34
|
+
klass.things << Thing.new
|
35
|
+
expect(klass.things.count).to eq(2)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'transforms correctly the collection' do
|
39
|
+
klass = TestClass.new(:things => [{a: 'foo'}, {b: 'bar'}])
|
40
|
+
expect(klass.things.count).to eq(2)
|
41
|
+
expect(klass.things.first.a).to eq('foo')
|
42
|
+
end
|
33
43
|
|
34
|
-
|
35
|
-
|
36
|
-
|
44
|
+
context 'when element is no a collection' do
|
45
|
+
subject {TestClass.new(:things => {a: 'foo'}).things}
|
46
|
+
it 'makes a new collection containing the element' do
|
47
|
+
expect(subject.count).to eq(1)
|
48
|
+
expect(subject.first.a).to eq('foo')
|
49
|
+
end
|
50
|
+
end
|
37
51
|
end
|
38
52
|
|
39
|
-
describe '
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
53
|
+
describe 'tag attributes' do
|
54
|
+
class TestAttributeClass < Model
|
55
|
+
tag_attributes :foo, :bar
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'dinamic method creation' do
|
59
|
+
it 'reads from the hash removing @' do
|
60
|
+
t = TestAttributeClass.new(:@foo => 'f', :@bar => 'b')
|
61
|
+
t.foo.should == 'f'
|
62
|
+
t.bar.should == 'b'
|
63
|
+
end
|
44
64
|
end
|
45
65
|
end
|
46
66
|
end
|
47
|
-
|
48
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: otis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thiago Bueno
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 2.
|
75
|
+
version: '2.3'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 2.
|
82
|
+
version: '2.3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: faraday
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- Rakefile
|
124
124
|
- lib/otis.rb
|
125
125
|
- lib/otis/client.rb
|
126
|
+
- lib/otis/error.rb
|
126
127
|
- lib/otis/hash_content.rb
|
127
128
|
- lib/otis/hooks.rb
|
128
129
|
- lib/otis/http_client.rb
|