Module: SoftLayer::ObjectFilterDefinitionContext
- Defined in:
- lib/softlayer/ObjectFilter.rb
Overview
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 pased 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.
Class Method Summary collapse
-
.begins_with(value) ⇒ Object
Matches when the value is found at the beginning of the field.
-
.contains(value) ⇒ Object
Matches when the value is found within the field the search is not case sensitive.
-
.contains_exactly(value) ⇒ Object
Matches when the value is found within the field the search is case sensitive.
-
.does_not_contain(value) ⇒ Object
Matches when the value is not found within the field the search is case sensitive.
-
.ends_with(value) ⇒ Object
Matches when the value is found at the end of the field.
-
.is(value) ⇒ Object
Matches when the value in the field is exactly equal to the given value.
-
.is_greater_or_equal_to(value) ⇒ Object
Matches when the value in the field is greater than or equal to the given value.
-
.is_greater_than(value) ⇒ Object
Matches when the value in the field is greater than the given value.
-
.is_less_or_equal_to(value) ⇒ Object
Matches when the value in the field is less than or equal to the given value.
-
.is_less_than(value) ⇒ Object
Matches when the value in the field is less than the given value.
-
.is_not(value) ⇒ Object
Matches is the value in the field does not exactly equal the value passed in.
-
.is_not_null ⇒ Object
Matches when the property’s value is not null.
-
.is_null ⇒ Object
Matches when the property’s value is null.
-
.matches_ignoring_case(value) ⇒ Object
Maches the given value in a case-insensitive way.
-
.matches_query(query_string) ⇒ Object
Accepts a query string defined by a simple query language.
-
.satisfies_the_raw_condition(condition_hash) ⇒ Object
This is a catch-all criteria matcher that allows for raw object filter conditions not covered by the more convenient methods above.
Class Method Details
.begins_with(value) ⇒ Object
Matches when the value is found at the beginning of the field. This search is not case sensitive
146 147 148 |
# File 'lib/softlayer/ObjectFilter.rb', line 146 def self.begins_with(value) filter_criteria('^=', value) end |
.contains(value) ⇒ Object
Matches when the value is found within the field the search is not case sensitive
140 141 142 |
# File 'lib/softlayer/ObjectFilter.rb', line 140 def self.contains(value) filter_criteria('*=', value) end |
.contains_exactly(value) ⇒ Object
Matches when the value is found within the field the search is case sensitive
183 184 185 |
# File 'lib/softlayer/ObjectFilter.rb', line 183 def self.contains_exactly(value) filter_criteria('~', value) end |
.does_not_contain(value) ⇒ Object
Matches when the value is not found within the field the search is case sensitive
189 190 191 |
# File 'lib/softlayer/ObjectFilter.rb', line 189 def self.does_not_contain(value) filter_criteria('!~', value) end |
.ends_with(value) ⇒ Object
Matches when the value is found at the end of the field. This search is not case sensitive
152 153 154 |
# File 'lib/softlayer/ObjectFilter.rb', line 152 def self.ends_with(value) filter_criteria('$=', value) end |
.is(value) ⇒ Object
Matches when the value in the field is exactly equal to the given value. This is a case-sensitive match
128 129 130 |
# File 'lib/softlayer/ObjectFilter.rb', line 128 def self.is(value) { 'operation' => value } end |
.is_greater_or_equal_to(value) ⇒ Object
Matches when the value in the field is greater than or equal to the given value
172 173 174 |
# File 'lib/softlayer/ObjectFilter.rb', line 172 def self.is_greater_or_equal_to(value) filter_criteria('>=', value) end |
.is_greater_than(value) ⇒ Object
Matches when the value in the field is greater than the given value
162 163 164 |
# File 'lib/softlayer/ObjectFilter.rb', line 162 def self.is_greater_than(value) filter_criteria('>', value) end |
.is_less_or_equal_to(value) ⇒ Object
Matches when the value in the field is less than or equal to the given value
177 178 179 |
# File 'lib/softlayer/ObjectFilter.rb', line 177 def self.is_less_or_equal_to(value) filter_criteria('<=', value) end |
.is_less_than(value) ⇒ Object
Matches when the value in the field is less than the given value
167 168 169 |
# File 'lib/softlayer/ObjectFilter.rb', line 167 def self.is_less_than(value) filter_criteria('<', value) end |
.is_not(value) ⇒ Object
Matches is the value in the field does not exactly equal the value passed in.
134 135 136 |
# File 'lib/softlayer/ObjectFilter.rb', line 134 def self.is_not(value) filter_criteria('!=', value) end |
.is_not_null ⇒ Object
Matches when the property’s value is not null
199 200 201 |
# File 'lib/softlayer/ObjectFilter.rb', line 199 def self.is_not_null() { 'operation' => 'not null' } end |
.is_null ⇒ Object
Matches when the property’s value is null
194 195 196 |
# File 'lib/softlayer/ObjectFilter.rb', line 194 def self.is_null { 'operation' => 'is null' } end |
.matches_ignoring_case(value) ⇒ Object
Maches the given value in a case-insensitive way
157 158 159 |
# File 'lib/softlayer/ObjectFilter.rb', line 157 def self.matches_ignoring_case(value) filter_criteria('_=', value) end |
.matches_query(query_string) ⇒ Object
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.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/softlayer/ObjectFilter.rb', line 230 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 |
.satisfies_the_raw_condition(condition_hash) ⇒ Object
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.
206 207 208 |
# File 'lib/softlayer/ObjectFilter.rb', line 206 def self.satisfies_the_raw_condition(condition_hash) condition_hash end |