omnis 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ Gemfile.lock
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 ||= default # if there is a default, apply it
24
- return value if value.is_a? Omnis::Operators::NullOperator
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 default
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 { |k,v| v.extract(@input_params) }.compact
65
- end
66
-
67
- # a list of keys that have been requested
68
- def keys
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
@@ -1,3 +1,3 @@
1
1
  module Omnis
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
@@ -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 "returns a list of keys that are requested" do
34
+ it "extracted operators contain the parameter name in the options" do
35
35
  t = TestBookingParams.new({"ref_anixe" => "1abc"})
36
- t.keys.should == [:ref_anixe]
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.0
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-25 00:00:00.000000000 Z
12
+ date: 2012-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport