Class: Braintree::AdvancedSearch

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

Overview

:nodoc:

Defined Under Namespace

Classes: EndsWithNode, 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.


149
150
151
# File 'lib/braintree/advanced_search.rb', line 149

def initialize
  @criteria = {}
end

Class Method Details

._create_field_accessors(fields, node_class) ⇒ Object


140
141
142
143
144
145
146
147
# File 'lib/braintree/advanced_search.rb', line 140

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


132
133
134
# File 'lib/braintree/advanced_search.rb', line 132

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

.ends_with_fields(*fields) ⇒ Object


136
137
138
# File 'lib/braintree/advanced_search.rb', line 136

def self.ends_with_fields(*fields)
  _create_field_accessors(fields, EndsWithNode)
end

.equality_fields(*fields) ⇒ Object


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

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

.is_fields(*fields) ⇒ Object


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

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

.key_value_fields(*fields) ⇒ Object


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

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

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


112
113
114
115
116
# File 'lib/braintree/advanced_search.rb', line 112

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


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

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


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

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

.range_fields(*fields) ⇒ Object


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

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

.text_fields(*fields) ⇒ Object


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

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

Instance Method Details

#add_criteria(key, value) ⇒ Object


153
154
155
156
157
158
159
# File 'lib/braintree/advanced_search.rb', line 153

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

#to_hashObject


161
162
163
# File 'lib/braintree/advanced_search.rb', line 161

def to_hash
  @criteria
end