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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZGM4ZjdiZmM3YjEyZDYzZGJhODAwMWEyYzU0ODliNmVlNDI4Mjk1OA==
4
+ MGJhMGRmNjE3ZDcyZmRjYmFmZTNlOGJlZmZkYTJmMDZiNDZkMjUzMw==
5
5
  data.tar.gz: !binary |-
6
- Mzc2M2JhZDE1MTFlYWVkOTJiNzA1ODZlZTYwZDc3MjQyYzNiZmQ0MQ==
6
+ MzJiOTU1ZjhlYTkyNjAzNmQ3NTcyNDZkMTRmNzQ4OWM4ZWU0MzNjMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmYxNjFlZWZjNjUwZTE0OTI5ZmUyNDAwYzFhNmYzYTY3MDM5ODk3YWEyMDRi
10
- ZWRmYmExNGU1ZTMyZmY2MDM3ZGUxMjhjODQ1MTNiZmRlNGM1ZWM1YTI0NmUw
11
- NzFiN2QxNzRmNGY1ZmI3YjQxYmMxZmY3NjA1Yjk3Y2M1MWU3Njg=
9
+ ZjlkZDJlMTIyMzU3ZGE4MTMxM2U3MzdkYTUyNjI2MTdhZWMwZDZiMjE0MWZl
10
+ Mjc4MTY4ZDBlMGM0M2VjM2RmNjJkMDQxZWZiOTM2ZDZkZDViNDY5NzdhMDZj
11
+ OGE0NTYwYmQ2M2UwZmE2ZGYzMTFkMGM1ZDZkYmIzOWQ5YTU0NWY=
12
12
  data.tar.gz: !binary |-
13
- MGM5ZWU3YzljNmRiNDAxNTJkZTFkZjIzMDg2MGViZjFiY2Q4YjlhZTgwZjNk
14
- MGY4NmJkN2YyOTMxNjBkYWZmMzZkYjJiMjQzODI5YWU3N2Q5NGNkMzRmMTg4
15
- NmFiYzFhZDZiMDhiNmJmNTUzYzMyMzZkNmFjYTdmNDExYmRlOWQ=
13
+ NTM1YzNkMjA4Njg5NGZjMjEyNGEyNWEwZmU1NzAyMmYzNWRkZDg5ODJjZTIy
14
+ NzAwMzllYmI2NGM4ZmYyOWMzMDIzMThlMDNlNTFjY2VlNTA3NDQzYmZjZWIx
15
+ OTRlMTM3NTNiMDljOGM1ODQ0ODk4YmFhYzE0MzUyZmRiYTBkN2E=
@@ -3,6 +3,7 @@ require "virtus"
3
3
  require "savon"
4
4
  require 'json'
5
5
  module Otis
6
+ require 'otis/error'
6
7
  require 'otis/hash_content'
7
8
  require 'otis/otis_object'
8
9
  require 'otis/model'
@@ -0,0 +1,4 @@
1
+ module Otis
2
+ class UnexpectedContentError < StandardError; end
3
+
4
+ end
@@ -5,9 +5,10 @@ module Otis
5
5
  base.extend(ClassExtension)
6
6
  end
7
7
 
8
- def initialize(attrs = {})
9
- @response = attrs
10
- attrs.each_pair do |k, v|
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} ||= Array(@response[:#{collection}]).map{|c| #{klass}.new(c)}; end)
32
+ class_eval %( def #{collection}; @#{collection} ||= [@response[:#{collection}]].compact.flatten.map{|c| #{klass}.new(c)}; end )
32
33
  end
33
34
 
34
35
  #
@@ -1,3 +1,3 @@
1
1
  module Otis
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -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.2.0'
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
- describe Otis::Object do
3
+ module Otis
4
+ describe Object do
4
5
 
5
- describe 'collection' do
6
- class Thing < Otis::Model
7
- attribute :a
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
- class TestClass
11
- include Otis::Object
12
- collection of: Thing, as: :things
13
- end
15
+ describe 'collection' do
16
+ class Thing < Model
17
+ attribute :a
18
+ end
14
19
 
15
- let(:klass) { TestClass.new }
20
+ class TestClass
21
+ include Object
22
+ collection of: Thing, as: :things
23
+ end
16
24
 
17
- it 'creates the get' do
18
- expect(klass).to respond_to(:things)
19
- end
25
+ let(:klass) { TestClass.new }
20
26
 
21
- it 'holds a collection' do
22
- klass.things << Thing.new
23
- klass.things << Thing.new
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
- it 'transforms correctly the collection' do
28
- klass = TestClass.new(:things => [{a: 'foo'}, {b: 'bar'}])
29
- expect(klass.things.count).to eq(2)
30
- expect(klass.things.first.a).to eq('foo')
31
- end
32
- end
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
- describe 'tag attributes' do
35
- class TestAttributeClass < Otis::Model
36
- tag_attributes :foo, :bar
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 'dinamic method creation' do
40
- it 'reads from the hash removing @' do
41
- t = TestAttributeClass.new(:@foo => 'f', :@bar => 'b')
42
- t.foo.should == 'f'
43
- t.bar.should == 'b'
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.6
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-02-26 00:00:00.000000000 Z
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.2.0
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.2.0
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