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

- (AdvancedSearch) initialize

Returns a new instance of AdvancedSearch



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

def initialize
  @criteria = {}
end

Class Method Details

+ (Object) _create_field_accessors(fields, node_class)



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

+ (Object) date_range_fields(*fields)



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

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

+ (Object) equality_fields(*fields)



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

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

+ (Object) is_fields(*fields)



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

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

+ (Object) key_value_fields(*fields)



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

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

+ (Object) multiple_value_field(field, options = {})



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

+ (Object) multiple_value_or_text_field(field, options = {})



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

+ (Object) partial_match_fields(*fields)



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

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

+ (Object) range_fields(*fields)



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

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

+ (Object) text_fields(*fields)



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

- (Object) add_criteria(key, value)



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

- (Object) to_hash



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

def to_hash
  @criteria
end