module SoftLayer::ObjectFilterDefinitionContext
The ObjectFilterDefinitionContext defines a bunch of methods that allow the property conditions of an object filter to be defined in a “pretty” way. Each method returns a block (a lambda, a proc) that, when called and passed the tail property of a property chain will generate a fragment of an object filter asking that that property match the given conditions.
This class, as a whole, is largely an implementation detail of object filter definitions and there is probably not a good reason to call into it directly.
Public Class Methods
Matches when the value is found at the beginning of the field. This search is not case sensitive
# File lib/softlayer/ObjectFilter.rb, line 148 def self.begins_with(value) filter_criteria('^=', value) end
Matches when the value is found within the field the search is not case sensitive
# File lib/softlayer/ObjectFilter.rb, line 142 def self.contains(value) filter_criteria('*=', value) end
Matches when the value is found within the field the search is case sensitive
# File lib/softlayer/ObjectFilter.rb, line 233 def self.contains_exactly(value) filter_criteria('~', value) end
Matches when the value is not found within the field the search is case sensitive
# File lib/softlayer/ObjectFilter.rb, line 239 def self.does_not_contain(value) filter_criteria('!~', value) end
Matches when the value is found at the end of the field. This search is not case sensitive
# File lib/softlayer/ObjectFilter.rb, line 154 def self.ends_with(value) filter_criteria('$=', value) end
Matches when the value in the field is exactly equal to the given value. This is a case-sensitive match If value is Enumerable, it is equivalent to calling ::is_contained_by
# File lib/softlayer/ObjectFilter.rb, line 129 def self.is(value) value.kind_of?(Enumerable) ? is_contained_by(value) : { 'operation' => value } end
Matches when the key path value is a date between the start and end dates provided Dates should be strings in '%m/%d/%Y %T' format or Date/DateTime instances
# File lib/softlayer/ObjectFilter.rb, line 165 def self.is_between_dates(start_date, end_date) { 'operation' => 'betweenDate', 'options' => [ { 'name' => 'startDate', 'value' => [ start_date.kind_of?(Date) ? start_date.strftime('%m/%d/%Y %T') : DateTime.strptime(start_date.to_s, '%m/%d/%Y %T').strftime('%m/%d/%Y %T') ] }, { 'name' => 'endDate', 'value' => [ end_date.kind_of?(Date) ? end_date.strftime('%m/%d/%Y %T') : DateTime.strptime(end_date.to_s, '%m/%d/%Y %T').strftime('%m/%d/%Y %T') ] } ] } end
Matches when key path value is equal to one of the given values in the Enumerable
# File lib/softlayer/ObjectFilter.rb, line 182 def self.is_contained_by(value) raise "Expected an Enumerable value with a list of acceptable values that can be converted to strings" unless value.kind_of?(Enumerable) { 'operation' => 'in', 'options' => [ { 'name' => 'data', 'value' => value.collect { |enum_val| enum_val.to_s } } ] } end
Matches when the value in the field is greater than or equal to the given value
# File lib/softlayer/ObjectFilter.rb, line 222 def self.is_greater_or_equal_to(value) filter_criteria('>=', value) end
Matches when the value in the field is greater than the given value
# File lib/softlayer/ObjectFilter.rb, line 212 def self.is_greater_than(value) filter_criteria('>', value) end
Matches when the value in the field is less than or equal to the given value
# File lib/softlayer/ObjectFilter.rb, line 227 def self.is_less_or_equal_to(value) filter_criteria('<=', value) end
Matches when the value in the field is less than the given value
# File lib/softlayer/ObjectFilter.rb, line 217 def self.is_less_than(value) filter_criteria('<', value) end
Matches is the value in the field does not exactly equal the value passed in. If value is Enumerable, it is equivalent to calling ::is_not_contained_by
# File lib/softlayer/ObjectFilter.rb, line 136 def self.is_not(value) value.kind_of?(Enumerable) ? is_not_contained_by(value) : filter_criteria('!=', value) end
Matches when key path value is not equal to one of the given values in the Enumerable
# File lib/softlayer/ObjectFilter.rb, line 197 def self.is_not_contained_by(value) raise "Expected an Enumerable value with a list of acceptable values that can be converted to strings" unless value.kind_of?(Enumerable) { 'operation' => 'not in', 'options' => [ { 'name' => 'data', 'value' => value.collect { |enum_val| enum_val.to_s } } ] } end
Matches when the property's value is not null
# File lib/softlayer/ObjectFilter.rb, line 249 def self.is_not_null() { 'operation' => 'not null' } end
Matches when the property's value is null
# File lib/softlayer/ObjectFilter.rb, line 244 def self.is_null { 'operation' => 'is null' } end
Matches the given value in a case-insensitive way
# File lib/softlayer/ObjectFilter.rb, line 159 def self.matches_ignoring_case(value) filter_criteria('_=', value) end
Accepts a query string defined by a simple query language. It translates strings in that language into criteria blocks
Object Filter comparisons can be done using operators. The set of accepted operators is found in the OBJECT_FILTER_OPERATORS array. The query string can consist of an operator followed by a space, followed by operand e.g.
"*= smaug"
The query language also accepts some aliases using asterisks in a regular-expression-like way. Those aliases look like:
'value' Exact value match (translates to '_= value') 'value*' Begins with value (translates to '^= value') '*value' Ends with value (translates to '$= value') '*value*' Contains value (translates to '*= value')
This method corresponds to the query_filter
method in the
SoftLayer-Python API.
# File lib/softlayer/ObjectFilter.rb, line 280 def self.matches_query(query_string) query = query_string.to_s.strip operator = OBJECT_FILTER_OPERATORS.find do | operator_string | query[0 ... operator_string.length] == operator_string end if operator then filter_criteria(operator, query[operator.length..-1]) else case query when /\A\*(.*)\*\Z/ contains($1) when /\A\*(.*)/ ends_with($1) when /\A(.*)\*\Z/ begins_with($1) else matches_ignoring_case(query) end #case end #if end
This is a catch-all criteria matcher that allows for raw object filter conditions not covered by the more convenient methods above. The name is intentionally, annoyingly long and you should use this routine with solid knowledge and great care.
# File lib/softlayer/ObjectFilter.rb, line 256 def self.satisfies_the_raw_condition(condition_hash) condition_hash end