legato 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.
@@ -26,13 +26,13 @@ module Legato
26
26
  end
27
27
  end
28
28
 
29
- # def set_instance_klass(klass)
30
- # @instance_klass = klass
31
- # end
29
+ def set_instance_klass(klass)
30
+ @instance_klass = klass
31
+ end
32
32
 
33
- # def instance_klass
34
- # @instance_klass || OpenStruct
35
- # end
33
+ def instance_klass
34
+ @instance_klass || OpenStruct
35
+ end
36
36
 
37
37
  def results(profile, options = {})
38
38
  Query.new(self).results(profile, options)
@@ -43,6 +43,10 @@ module Legato
43
43
  # end
44
44
  end
45
45
 
46
+ def instance_klass
47
+ @parent_klass.instance_klass
48
+ end
49
+
46
50
  def apply_filter(*args, &block)
47
51
  @profile = extract_profile(args)
48
52
 
@@ -20,7 +20,7 @@ module Legato
20
20
  access_token.get(URL, :params => query.to_params)
21
21
  end
22
22
 
23
- Response.new(raw_response)
23
+ Response.new(raw_response, query.instance_klass)
24
24
  end
25
25
 
26
26
  # Management
@@ -1,3 +1,3 @@
1
1
  module Legato
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -32,6 +32,16 @@ describe "Legato::Model" do
32
32
  @model.dimensions.should == Legato::ListParameter.new(:dimensions, [:browser, :city])
33
33
  end
34
34
 
35
+ it 'knows the instance class it should use' do
36
+ klass = Class.new
37
+ @model.set_instance_klass(klass)
38
+ @model.instance_klass.should == klass
39
+ end
40
+
41
+ it "defaults to OpenStruct for its instance class" do
42
+ @model.instance_klass.should == OpenStruct
43
+ end
44
+
35
45
  context "with filters" do
36
46
  before :each do
37
47
  @block = lambda {}
@@ -46,6 +46,12 @@ describe Legato::Query do
46
46
  @query.loaded?.should == false
47
47
  end
48
48
 
49
+ it 'delegates the instance klass from the parent klass' do
50
+ klass = Class.new
51
+ @query.parent_klass.stubs(:instance_klass).returns(klass)
52
+ @query.instance_klass.should == klass
53
+ end
54
+
49
55
  it "loads a collection of results" do
50
56
  response = stub(:collection => [], :total_results => 0, :totals_for_all_results => {})
51
57
  user = stub(:request => response)
@@ -8,12 +8,13 @@ describe Legato::User do
8
8
  end
9
9
 
10
10
  it 'returns a response for a given query' do
11
+ klass = Class.new
11
12
  @access_token.stubs(:get).returns('a response')
12
13
  Legato::Response.stubs(:new)
13
14
 
14
- @user.request(stub(:to_params => "params"))
15
+ @user.request(stub(:to_params => "params", :instance_klass => klass))
15
16
 
16
- Legato::Response.should have_received(:new).with('a response')
17
+ Legato::Response.should have_received(:new).with('a response', klass)
17
18
  @access_token.should have_received(:get).with(Legato::User::URL, :params => "params")
18
19
  end
19
20
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legato
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tony Pitale
@@ -80,7 +80,7 @@ dependencies:
80
80
  requirements:
81
81
  - - "="
82
82
  - !ruby/object:Gem::Version
83
- hash: 3111266077
83
+ hash: -2540839718
84
84
  segments:
85
85
  - 2
86
86
  - 0