omnis 0.1.1 → 0.2.0

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.
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ --order rand
@@ -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.concat(extra_fields)
73
+ fields = self.class.field_list + extra_fields
74
74
  { :limit => items_per_page, :skip => skip, :fields => fields }
75
75
  end
76
76
  end
@@ -18,6 +18,8 @@ module Omnis
18
18
  end
19
19
  end
20
20
 
21
+ Any = NullOperator
22
+
21
23
  class Matches < NullOperator
22
24
  end
23
25
 
@@ -31,14 +31,15 @@ module Omnis
31
31
  @properties ||= {}
32
32
  end
33
33
 
34
- # if an expr is provided it will be passed to the configured extractor,
35
- # otherwise a block is required
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
- raise ArgumentError if (expr.nil? && block.nil?)
38
-
39
- xtr = case expr
40
- when String; @extractor.extractor(expr)
41
- when nil ; block
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
@@ -1,3 +1,3 @@
1
1
  module Omnis
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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 = p t.to_mongo
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"
@@ -62,4 +62,5 @@ describe Omnis::Query do
62
62
  t = TestDefaultsWithLambdaParams.new({})
63
63
  t.fetch(:contract).value.should == :angry_nerds
64
64
  end
65
+
65
66
  end
@@ -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 tranformer lambda' do
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.1.1
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-10-22 00:00:00.000000000 Z
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