omnis 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +3 -0
- data/lib/omnis/mongo_query.rb +1 -1
- data/lib/omnis/operators.rb +2 -0
- data/lib/omnis/transformer.rb +8 -7
- data/lib/omnis/version.rb +1 -1
- data/spec/lib/omnis/mongo_query_spec.rb +1 -1
- data/spec/lib/omnis/query_spec.rb +1 -0
- data/spec/lib/omnis/transformer_spec.rb +15 -10
- metadata +3 -2
data/.rspec
ADDED
data/lib/omnis/mongo_query.rb
CHANGED
@@ -70,7 +70,7 @@ module Omnis
|
|
70
70
|
def mongo_opts(extracted_params)
|
71
71
|
params_with_extra_fields = extracted_params.collect(&:opts).select {|e| e.has_key? :field}
|
72
72
|
extra_fields = params_with_extra_fields.map {|e| e[:field]}
|
73
|
-
fields = self.class.field_list
|
73
|
+
fields = self.class.field_list + extra_fields
|
74
74
|
{ :limit => items_per_page, :skip => skip, :fields => fields }
|
75
75
|
end
|
76
76
|
end
|
data/lib/omnis/operators.rb
CHANGED
data/lib/omnis/transformer.rb
CHANGED
@@ -31,14 +31,15 @@ module Omnis
|
|
31
31
|
@properties ||= {}
|
32
32
|
end
|
33
33
|
|
34
|
-
#
|
35
|
-
# otherwise a block
|
34
|
+
# If an expr is provided it will be passed to the configured extractor,
|
35
|
+
# otherwise a block should be given. As last resort, it embeds a lambda to
|
36
|
+
# look for a class method with the name of the param (at runtime)
|
36
37
|
def property(name, expr=nil, opts={}, &block)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
xtr = case
|
39
|
+
when String === expr ; @extractor.extractor(expr)
|
40
|
+
when block_given? ; block
|
41
|
+
else
|
42
|
+
->(source) { self.send(name, source) }
|
42
43
|
end
|
43
44
|
|
44
45
|
Omnis::Transformer::Property.new(name, expr, opts, xtr).tap do |prop|
|
data/lib/omnis/version.rb
CHANGED
@@ -96,7 +96,7 @@ describe Omnis::MongoQuery do
|
|
96
96
|
|
97
97
|
it "should fill params with default" do
|
98
98
|
t = TestHotelsWithDepartureTomorrowQuery.new({})
|
99
|
-
m =
|
99
|
+
m = t.to_mongo
|
100
100
|
m.selector[:contract].should == /^wotra./i
|
101
101
|
m.selector[:product].should == "PACKAGE"
|
102
102
|
m.selector[:status].should == "book_confirmed"
|
@@ -37,15 +37,6 @@ describe Omnis::Transformer do
|
|
37
37
|
t.transform(doc).should == { :ref => "1abc" }
|
38
38
|
end
|
39
39
|
|
40
|
-
it "should raise an ArgumentError if no block and no expression provided" do
|
41
|
-
expect {
|
42
|
-
class TestTransformerInvalid
|
43
|
-
include Omnis::Transformer
|
44
|
-
property :ref
|
45
|
-
end
|
46
|
-
}.to raise_error ArgumentError
|
47
|
-
end
|
48
|
-
|
49
40
|
it "uses a #to_object method if provided to convert the resulting Hash into an Object" do
|
50
41
|
class TestTransformerWithToObject
|
51
42
|
include Omnis::Transformer
|
@@ -58,7 +49,7 @@ describe Omnis::Transformer do
|
|
58
49
|
t.transform(doc).should == OpenStruct.new(ref: "1abc")
|
59
50
|
end
|
60
51
|
|
61
|
-
it 'provides a
|
52
|
+
it 'provides a transformer lambda' do
|
62
53
|
class TestXformer
|
63
54
|
include Omnis::Transformer
|
64
55
|
property(:ref) {|src| src['ref_anixe']}
|
@@ -68,4 +59,18 @@ describe Omnis::Transformer do
|
|
68
59
|
xformer.should be_a Proc
|
69
60
|
xformer.({"ref_anixe" => "2two"}).should == {:ref => "2two"}
|
70
61
|
end
|
62
|
+
|
63
|
+
it 'works with built in (class) methods' do
|
64
|
+
class TestBuiltInXformer
|
65
|
+
include Omnis::Transformer
|
66
|
+
property :ref
|
67
|
+
|
68
|
+
def self.ref(source)
|
69
|
+
"ref_value"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
xformer = TestBuiltInXformer.new.to_proc
|
74
|
+
xformer.({}).should == {:ref => 'ref_value'}
|
75
|
+
end
|
71
76
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omnis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
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-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -163,6 +163,7 @@ extensions: []
|
|
163
163
|
extra_rdoc_files: []
|
164
164
|
files:
|
165
165
|
- .gitignore
|
166
|
+
- .rspec
|
166
167
|
- Gemfile
|
167
168
|
- Guardfile
|
168
169
|
- LICENSE.txt
|