Class: Braintree::AdvancedSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/braintree/advanced_search.rb

Overview

:nodoc:

Defined Under Namespace

Classes: EqualityNode, IsNode, KeyValueNode, MultipleValueNode, MultipleValueOrTextNode, PartialMatchNode, RangeNode, SearchNode, TextNode

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAdvancedSearch

Returns a new instance of AdvancedSearch



141
142
143
# File 'lib/braintree/advanced_search.rb', line 141

def initialize
  @criteria = {}
end

Class Method Details

._create_field_accessors(fields, node_class) ⇒ Object



132
133
134
135
136
137
138
139
# File 'lib/braintree/advanced_search.rb', line 132

def self._create_field_accessors(fields, node_class)
  fields.each do |field|
    define_method(field) do |*args|
      raise "An operator is required" unless args.empty?
      node_class.new(field, self)
    end
  end
end

.date_range_fields(*fields) ⇒ Object



128
129
130
# File 'lib/braintree/advanced_search.rb', line 128

def self.date_range_fields(*fields)
  _create_field_accessors(fields, DateRangeNode)
end

.equality_fields(*fields) ⇒ Object



96
97
98
# File 'lib/braintree/advanced_search.rb', line 96

def self.equality_fields(*fields)
  _create_field_accessors(fields, EqualityNode)
end

.is_fields(*fields) ⇒ Object



100
101
102
# File 'lib/braintree/advanced_search.rb', line 100

def self.is_fields(*fields)
  _create_field_accessors(fields, IsNode)
end

.key_value_fields(*fields) ⇒ Object



120
121
122
# File 'lib/braintree/advanced_search.rb', line 120

def self.key_value_fields(*fields)
  _create_field_accessors(fields, KeyValueNode)
end

.multiple_value_field(field, options = {}) ⇒ Object



108
109
110
111
112
# File 'lib/braintree/advanced_search.rb', line 108

def self.multiple_value_field(field, options={})
  define_method(field) do
    MultipleValueNode.new(field, self, options)
  end
end

.multiple_value_or_text_field(field, options = {}) ⇒ Object



114
115
116
117
118
# File 'lib/braintree/advanced_search.rb', line 114

def self.multiple_value_or_text_field(field, options={})
  define_method(field) do
    MultipleValueOrTextNode.new(field, self, options)
  end
end

.partial_match_fields(*fields) ⇒ Object



104
105
106
# File 'lib/braintree/advanced_search.rb', line 104

def self.partial_match_fields(*fields)
  _create_field_accessors(fields, PartialMatchNode)
end

.range_fields(*fields) ⇒ Object



124
125
126
# File 'lib/braintree/advanced_search.rb', line 124

def self.range_fields(*fields)
  _create_field_accessors(fields, RangeNode)
end

.text_fields(*fields) ⇒ Object



92
93
94
# File 'lib/braintree/advanced_search.rb', line 92

def self.text_fields(*fields)
  _create_field_accessors(fields, TextNode)
end

Instance Method Details

#add_criteria(key, value) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/braintree/advanced_search.rb', line 145

def add_criteria(key, value)
  if @criteria[key].is_a?(Hash)
    @criteria[key].merge!(value)
  else
    @criteria[key] = value
  end
end

#to_hashObject



153
154
155
# File 'lib/braintree/advanced_search.rb', line 153

def to_hash
  @criteria
end