otis 0.0.5 → 0.0.6

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
- NjNlNDM2YzIxMTJhOTU3M2QzMjRjMTFjM2ZiOGVhYjc3N2NmYTRmYw==
4
+ ZGM4ZjdiZmM3YjEyZDYzZGJhODAwMWEyYzU0ODliNmVlNDI4Mjk1OA==
5
5
  data.tar.gz: !binary |-
6
- NWJmNjRiNDk0YmY3NTdkOTA5NzY2ZjEwOTAyYjk4NTczNGNkYzVjZg==
6
+ Mzc2M2JhZDE1MTFlYWVkOTJiNzA1ODZlZTYwZDc3MjQyYzNiZmQ0MQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZmZlYzU1M2E5MzYxYTg0MmI3NDI4MDBhMzBkNDcwZDUxM2IyNWQxNGRlMWNi
10
- NDk1NThmYTVkMjIzNTM4MDZlMDM0YWJjYTBkYjdmNTJkZmNiZDhhZmY4ZmUz
11
- NTMzMGFhMzY4ZmJlMGUyZTI4NTJlZDM3ZDRmNWRjMWRjNzk2YTc=
9
+ NmYxNjFlZWZjNjUwZTE0OTI5ZmUyNDAwYzFhNmYzYTY3MDM5ODk3YWEyMDRi
10
+ ZWRmYmExNGU1ZTMyZmY2MDM3ZGUxMjhjODQ1MTNiZmRlNGM1ZWM1YTI0NmUw
11
+ NzFiN2QxNzRmNGY1ZmI3YjQxYmMxZmY3NjA1Yjk3Y2M1MWU3Njg=
12
12
  data.tar.gz: !binary |-
13
- Yzg3NjgxYTc4YTJlN2MxZGU5Y2M4M2Y4YWE5NzkxN2RhYTgyMzQ3NzZlZjE5
14
- MGE5NzZiMTM3YWZhOWYzMGM0OTFkZTJjNzRlZDk2ZTUxOWQzZDM0NWZlOTk0
15
- YjhlOTc0ZmEzNzNjMGEzODJkYjE0ZjQwODNlODc1MzY4YzlkZmI=
13
+ MGM5ZWU3YzljNmRiNDAxNTJkZTFkZjIzMDg2MGViZjFiY2Q4YjlhZTgwZjNk
14
+ MGY4NmJkN2YyOTMxNjBkYWZmMzZkYjJiMjQzODI5YWU3N2Q5NGNkMzRmMTg4
15
+ NmFiYzFhZDZiMDhiNmJmNTUzYzMyMzZkNmFjYTdmNDExYmRlOWQ=
@@ -20,10 +20,47 @@ module Otis
20
20
  end
21
21
  end
22
22
 
23
+ #
24
+ # This method allows a dynamic generation a list of node in a parent one.
25
+ # It differs slightly from Virtus mapping in a way that it guarantess that
26
+ # a return of a collection is always an array and never a nil object
27
+ #
23
28
  def collection(opts ={})
24
29
  collection = opts[:as].to_s
25
30
  klass = opts[:of]
26
- class_eval %(def #{collection}; @#{collection} ||= Array(@response['#{camelize(collection)}']).map{|c| #{klass}.new(c)}; end)
31
+ class_eval %(def #{collection}; @#{collection} ||= Array(@response[:#{collection}]).map{|c| #{klass}.new(c)}; end)
32
+ end
33
+
34
+ #
35
+ # When Savon receives a response with attributes in its tags, it creates
36
+ # keys that start with '@' sign, which breaks in the Virtus object
37
+ # transformation.
38
+ # This method allows the mapping of an attribute that would be originally
39
+ # ignored by Virtus. See the example below:
40
+ #
41
+ # <response duration="123">
42
+ # <tag>Foo</tag>
43
+ # </response>
44
+ #
45
+ # In order to create the right mapper, the following needs to be done:
46
+ #
47
+ # class YourObject < Otis::Model
48
+ # tag_attribute :duration
49
+ # attribute :tag
50
+ # end
51
+ #
52
+ # yourObject.tag # => "Foo"
53
+ # yourObject.duration #=> 123
54
+ #
55
+ #
56
+ def tag_attributes(*args)
57
+ args.each do |m|
58
+ class_eval %(
59
+ def #{m}
60
+ @response[:@#{m}]
61
+ end
62
+ )
63
+ end
27
64
  end
28
65
 
29
66
  private
@@ -11,7 +11,7 @@ module Otis
11
11
 
12
12
  protected
13
13
  def call(action, options)
14
- soap_response = @client.call(action, options.first).body
14
+ soap_response = @client.call(action, options).body
15
15
  soap_response
16
16
  end
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module Otis
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -3,12 +3,15 @@ require 'spec_helper'
3
3
  describe Otis::Object do
4
4
 
5
5
  describe 'collection' do
6
- class Thing; end
6
+ class Thing < Otis::Model
7
+ attribute :a
8
+ end
7
9
 
8
10
  class TestClass
9
11
  include Otis::Object
10
12
  collection of: Thing, as: :things
11
13
  end
14
+
12
15
  let(:klass) { TestClass.new }
13
16
 
14
17
  it 'creates the get' do
@@ -20,5 +23,26 @@ describe Otis::Object do
20
23
  klass.things << Thing.new
21
24
  expect(klass.things.count).to eq(2)
22
25
  end
26
+
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
23
32
  end
33
+
34
+ describe 'tag attributes' do
35
+ class TestAttributeClass < Otis::Model
36
+ tag_attributes :foo, :bar
37
+ end
38
+
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'
44
+ end
45
+ end
46
+ end
47
+
24
48
  end
@@ -23,7 +23,7 @@ describe Otis::SoapClient do
23
23
  before { client.stub_chain(:call, :body).and_return(response) }
24
24
 
25
25
  it 'delegates the call the the client' do
26
- client.should_receive(:call).with(:my_call, [:params, []])
26
+ client.should_receive(:call).with(:my_call, {:params => []})
27
27
  MySoapClient.new(routes, double).my_call(params: [])
28
28
  end
29
29
 
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.5
4
+ version: 0.0.6
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-25 00:00:00.000000000 Z
11
+ date: 2014-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler