query-interface-client 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44b324471ab51bbfbfea31b81b786222ba6ed93c
4
- data.tar.gz: c2832d16059ef08bf3550a52650d5d7d45d77605
3
+ metadata.gz: aeee92f6abcc5feadfe736a221026538f7051135
4
+ data.tar.gz: e6ce1dbe30515ce5d940afd55755039705b63ae7
5
5
  SHA512:
6
- metadata.gz: 7362b6243695be96cb8baf5c12190d1a4d961b6df88b74100b03ba7ffc934903d4d9fe627c3bcb57466e1882cbeb902bb6addb22f487c319ae0205440e00385e
7
- data.tar.gz: 962f9ec542ddd72ca44924658c98ff7b55058527bc4c2f4df0afd32a736f87bd9f1c32e3810db140f8b50a850f626c9e499a0eafb02e97df33cea41892d29e24
6
+ metadata.gz: 1716f5e0fbad420ac7ab614f4522063452b00f66efac17a172aaae94fc99219311f4c8e876bfe128b20c3d1eb67ec970ed1808b7174ea5eecfc601e97e33ffe6
7
+ data.tar.gz: b2d38e50e12f0c4de3487a8674c87d2fa4f60f02cee8bac6c770b558a38d5becd1ed8fde8500d1ef6a698c97a3390e33483f67b0870dc81d4bf8c1b38c884aeb
@@ -17,6 +17,15 @@ module QueryInterface::Client
17
17
  def query
18
18
  LazyQuery.new(self)
19
19
  end
20
+
21
+ def association(name, class_name: nil, dataset: nil)
22
+ dataset ||= name
23
+ define_method(name) do
24
+ klass = (class_name || name.to_s.singularize.camelize).constantize
25
+ self.class.query.instance(self.id).context(dataset, klass)
26
+ end
27
+ end
28
+
20
29
  end
21
30
 
22
31
  end
@@ -1,7 +1,7 @@
1
1
  module QueryInterface
2
2
  module Client
3
3
 
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
 
6
6
  end
7
7
  end
@@ -114,39 +114,39 @@ describe QueryInterface::Client::LazyQuery do
114
114
  end
115
115
  end
116
116
 
117
- context "first" do
118
- let(:transformations) {[transformation: :first, parameter: nil]}
119
- it "gets the first object via do_query" do
117
+ context 'first' do
118
+ it 'gets the first object' do
120
119
  query = subject.new(model)
121
- query.should_receive(:copy).and_return(query)
122
- query.should_receive(:do_query)
123
- query.first
124
- query.transformations.should eq(self.transformations)
120
+ result = double('result')
121
+ query.should_receive(:one).with(:first).and_return(result)
122
+ query.first.should be(result)
125
123
  end
124
+ end
126
125
 
127
- it "uses the cached result" do
126
+ context 'last' do
127
+ it 'gets the last object' do
128
128
  query = subject.new(model)
129
- query.result = ["a", "b", "c"]
130
- query.should_not_receive(:do_raw_query)
131
- query.first.should eq("a")
129
+ result = double('result')
130
+ query.should_receive(:one).with(:last).and_return(result)
131
+ query.last.should be(result)
132
132
  end
133
133
  end
134
134
 
135
- context "last" do
136
- let(:transformations) {[transformation: :last, parameter: nil]}
137
- it "gets the last object via do_query" do
135
+ context 'one' do
136
+ it 'gets one object' do
138
137
  query = subject.new(model)
138
+ result = double('result')
139
139
  query.should_receive(:copy).and_return(query)
140
- query.should_receive(:do_query)
141
- query.last
142
- query.transformations.should eq(self.transformations)
140
+ query.should_receive(:do_query).and_return(result)
141
+ query.result.should be_nil
142
+ query.send(:one, :anyone).should be(result)
143
+ query.transformations.should eq([{transformation: :anyone, parameter: nil}])
143
144
  end
144
-
145
145
  it "uses the cached result" do
146
146
  query = subject.new(model)
147
147
  query.result = ["a", "b", "c"]
148
- query.should_not_receive(:do_raw_query)
149
- query.last.should eq("c")
148
+ query.should_not_receive(:do_query)
149
+ query.first.should eq("a")
150
150
  end
151
151
  end
152
152
 
@@ -187,7 +187,7 @@ describe QueryInterface::Client::LazyQuery do
187
187
  it "adds a map_ids transformation" do
188
188
  query = subject.new(model)
189
189
  query.should_receive(:copy).and_return(query)
190
- query.stub!(:do_raw_query).and_return({parsed_data: {data: [1,2,3]}})
190
+ query.stub(:do_raw_query).and_return({parsed_data: {data: [1,2,3]}})
191
191
  query.ids
192
192
  query.transformations.should eq(self.transformations)
193
193
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: query-interface-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Kopecky <andreas.kopecky@radarservices.com>
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-01-14 00:00:00.000000000 Z
13
+ date: 2014-01-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: her
@@ -128,4 +128,3 @@ signing_key:
128
128
  specification_version: 4
129
129
  summary: Client for the radar query interface
130
130
  test_files: []
131
- has_rdoc: