omnis 0.6.0 → 0.6.1
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/.gitignore +1 -0
- data/lib/omnis/query.rb +14 -9
- data/lib/omnis/version.rb +1 -1
- data/spec/lib/omnis/query_spec.rb +3 -2
- metadata +2 -2
data/.gitignore
CHANGED
data/lib/omnis/query.rb
CHANGED
@@ -20,16 +20,21 @@ module Omnis
|
|
20
20
|
# extracts the value for a param, using the extractor lamba or the default value
|
21
21
|
def extract(params)
|
22
22
|
value = @extractor.(params) if params.keys.include? name # only run extractor if the param was in the request (params)
|
23
|
-
value ||=
|
24
|
-
return value if
|
23
|
+
value ||= default_value # if there is a default, apply it
|
24
|
+
return value if extracted_result_is_an_operator? value
|
25
25
|
return @operator.new(@name, value, @opts) unless value.nil?
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def default_value
|
29
29
|
expr = @opts[:default]
|
30
30
|
return expr.call if expr.is_a? Proc
|
31
31
|
return expr
|
32
32
|
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def extracted_result_is_an_operator?(value)
|
36
|
+
value.is_a? Omnis::Operators::NullOperator
|
37
|
+
end
|
33
38
|
end
|
34
39
|
|
35
40
|
def self.included(base)
|
@@ -60,13 +65,13 @@ module Omnis
|
|
60
65
|
self.class.params.fetch(name).extract(@input_params)
|
61
66
|
end
|
62
67
|
|
68
|
+
# extracts operators from params
|
63
69
|
def extract
|
64
|
-
self.class.params.map
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
extract.map(&:key)
|
70
|
+
self.class.params.map do |k,v|
|
71
|
+
v.extract(@input_params).tap do |operator|
|
72
|
+
operator.opts[:param_name] = k unless operator.nil?
|
73
|
+
end
|
74
|
+
end.compact
|
70
75
|
end
|
71
76
|
end
|
72
77
|
end
|
data/lib/omnis/version.rb
CHANGED
@@ -31,10 +31,11 @@ describe Omnis::Query do
|
|
31
31
|
t.fetch(:ref_anixe).should == Omnis::Operators::Matches.new(:ref_anixe, "1abc")
|
32
32
|
end
|
33
33
|
|
34
|
-
it "
|
34
|
+
it "extracted operators contain the parameter name in the options" do
|
35
35
|
t = TestBookingParams.new({"ref_anixe" => "1abc"})
|
36
|
-
t.
|
36
|
+
t.extract.map { |e| e.opts[:param_name] }.should == [:ref_anixe]
|
37
37
|
end
|
38
|
+
|
38
39
|
it "allows to extract all at once" do
|
39
40
|
t = TestBookingParams.new({"ref_anixe" => "1abc"})
|
40
41
|
t.extract.should == [Omnis::Operators::Matches.new(:ref_anixe, "1abc")]
|
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.6.
|
4
|
+
version: 0.6.1
|
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-11-
|
12
|
+
date: 2012-11-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|