hyperion-api 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hyperion.rb +12 -2
- data/lib/hyperion/dev/ds_spec.rb +8 -0
- data/spec/hyperion/shared_examples.rb +4 -0
- data/spec/hyperion_spec.rb +7 -4
- metadata +14 -14
data/lib/hyperion.rb
CHANGED
@@ -3,6 +3,7 @@ require 'hyperion/filter'
|
|
3
3
|
require 'hyperion/sort'
|
4
4
|
require 'hyperion/util'
|
5
5
|
require 'hyperion/format'
|
6
|
+
require 'hyperion/types'
|
6
7
|
|
7
8
|
module Hyperion
|
8
9
|
|
@@ -137,15 +138,16 @@ module Hyperion
|
|
137
138
|
|
138
139
|
def self.build_query(kind, args)
|
139
140
|
kind = Format.format_kind(kind)
|
140
|
-
filters = build_filters(args[:filters])
|
141
|
+
filters = build_filters(kind, args[:filters])
|
141
142
|
sorts = build_sorts(args[:sorts])
|
142
143
|
Query.new(kind, filters, sorts, args[:limit], args[:offset])
|
143
144
|
end
|
144
145
|
|
145
|
-
def self.build_filters(filters)
|
146
|
+
def self.build_filters(kind, filters)
|
146
147
|
(filters || []).map do |(field, operator, value)|
|
147
148
|
operator = Format.format_operator(operator)
|
148
149
|
field = Format.format_field(field)
|
150
|
+
value = pack_value(kind, field, value)
|
149
151
|
Filter.new(field, operator, value)
|
150
152
|
end
|
151
153
|
end
|
@@ -187,6 +189,14 @@ module Hyperion
|
|
187
189
|
end
|
188
190
|
end
|
189
191
|
|
192
|
+
def self.pack_value(kind, field, value)
|
193
|
+
kind_spec = kind_spec_for(kind)
|
194
|
+
return value unless kind_spec
|
195
|
+
field_spec = kind_spec.fields[field]
|
196
|
+
return value unless field_spec
|
197
|
+
return field_spec.pack(value)
|
198
|
+
end
|
199
|
+
|
190
200
|
def self.packer_for(type)
|
191
201
|
@packers[type]
|
192
202
|
end
|
data/lib/hyperion/dev/ds_spec.rb
CHANGED
@@ -284,5 +284,13 @@ shared_examples_for 'Datastore' do
|
|
284
284
|
found_shirt[:account_key].should == account_key
|
285
285
|
found_account[:key].should == account_key
|
286
286
|
end
|
287
|
+
|
288
|
+
it 'filters on foreign keys' do
|
289
|
+
account = api.save(:kind => :account)
|
290
|
+
account_key = account[:key]
|
291
|
+
shirt = api.save(:kind => :shirt, :account_key => account_key)
|
292
|
+
found_shirts = api.find_by_kind(:shirt, :filters => [[:account_key, '=', account_key]])
|
293
|
+
found_shirts[0].should == shirt
|
294
|
+
end
|
287
295
|
end
|
288
296
|
end
|
@@ -289,5 +289,9 @@ shared_examples_for 'filtering' do |actor|
|
|
289
289
|
it 'passes the value to the filter' do
|
290
290
|
actor.call([:attr, '=', 0]).value.should == 0
|
291
291
|
end
|
292
|
+
|
293
|
+
it 'packs filter values' do
|
294
|
+
actor.call([:test, '=', 0]).value.should == 'i was packed'
|
295
|
+
end
|
292
296
|
end
|
293
297
|
|
data/spec/hyperion_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'hyperion'
|
2
|
-
require 'hyperion/types'
|
3
2
|
require 'hyperion/shared_examples'
|
4
3
|
require 'hyperion/fake_ds'
|
5
4
|
|
@@ -9,6 +8,10 @@ describe Hyperion do
|
|
9
8
|
Hyperion
|
10
9
|
end
|
11
10
|
|
11
|
+
Hyperion.defentity(:filtering) do |kind|
|
12
|
+
kind.field(:test, :packer => lambda { |value| 'i was packed' })
|
13
|
+
end
|
14
|
+
|
12
15
|
context 'datastore' do
|
13
16
|
it 'will throw an error if the datastore is called before assignment' do
|
14
17
|
expect{ subject.datastore }.to raise_error
|
@@ -151,7 +154,7 @@ describe Hyperion do
|
|
151
154
|
|
152
155
|
context 'parses filters' do
|
153
156
|
include_examples 'filtering', lambda { |filter|
|
154
|
-
Hyperion.find_by_kind('
|
157
|
+
Hyperion.find_by_kind('filtering', :filters => [filter])
|
155
158
|
Hyperion.datastore.queries.last.filters.first
|
156
159
|
}
|
157
160
|
end
|
@@ -217,7 +220,7 @@ describe Hyperion do
|
|
217
220
|
|
218
221
|
context 'parses filters' do
|
219
222
|
include_examples 'filtering', lambda { |filter|
|
220
|
-
Hyperion.delete_by_kind('
|
223
|
+
Hyperion.delete_by_kind('filtering', :filters => [filter])
|
221
224
|
Hyperion.datastore.queries.last.filters.first
|
222
225
|
}
|
223
226
|
end
|
@@ -238,7 +241,7 @@ describe Hyperion do
|
|
238
241
|
|
239
242
|
context 'parses filters' do
|
240
243
|
include_examples 'filtering', lambda { |filter|
|
241
|
-
Hyperion.count_by_kind('
|
244
|
+
Hyperion.count_by_kind('filtering', :filters => [filter])
|
242
245
|
Hyperion.datastore.queries.last.filters.first
|
243
246
|
}
|
244
247
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hyperion-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -50,22 +50,22 @@ executables: []
|
|
50
50
|
extensions: []
|
51
51
|
extra_rdoc_files: []
|
52
52
|
files:
|
53
|
-
- lib/hyperion
|
54
|
-
- lib/hyperion/
|
53
|
+
- lib/hyperion.rb
|
54
|
+
- lib/hyperion/query.rb
|
55
|
+
- lib/hyperion/memory.rb
|
55
56
|
- lib/hyperion/util.rb
|
56
|
-
- lib/hyperion/
|
57
|
+
- lib/hyperion/format.rb
|
57
58
|
- lib/hyperion/key.rb
|
58
|
-
- lib/hyperion/memory.rb
|
59
59
|
- lib/hyperion/sort.rb
|
60
|
-
- lib/hyperion/query.rb
|
61
60
|
- lib/hyperion/types.rb
|
62
|
-
- lib/hyperion.rb
|
61
|
+
- lib/hyperion/filter.rb
|
62
|
+
- lib/hyperion/dev/ds_spec.rb
|
63
63
|
- spec/hyperion_spec.rb
|
64
|
-
- spec/hyperion/util_spec.rb
|
65
|
-
- spec/hyperion/key_spec.rb
|
66
|
-
- spec/hyperion/shared_examples.rb
|
67
64
|
- spec/hyperion/memory_spec.rb
|
65
|
+
- spec/hyperion/key_spec.rb
|
68
66
|
- spec/hyperion/fake_ds.rb
|
67
|
+
- spec/hyperion/util_spec.rb
|
68
|
+
- spec/hyperion/shared_examples.rb
|
69
69
|
homepage: https://github.com/mylesmegyesi/hyperion-ruby
|
70
70
|
licenses:
|
71
71
|
- Eclipse Public License
|
@@ -93,8 +93,8 @@ specification_version: 3
|
|
93
93
|
summary: A Generic Persistence API for Ruby
|
94
94
|
test_files:
|
95
95
|
- spec/hyperion_spec.rb
|
96
|
-
- spec/hyperion/util_spec.rb
|
97
|
-
- spec/hyperion/key_spec.rb
|
98
|
-
- spec/hyperion/shared_examples.rb
|
99
96
|
- spec/hyperion/memory_spec.rb
|
97
|
+
- spec/hyperion/key_spec.rb
|
100
98
|
- spec/hyperion/fake_ds.rb
|
99
|
+
- spec/hyperion/util_spec.rb
|
100
|
+
- spec/hyperion/shared_examples.rb
|