Module: EnotasApi::Filterable::ClassMethods
- Defined in:
- lib/enotas_api/support/filterable.rb
Constant Summary collapse
- FILTER_HANDLERS =
{ eq: ->(field, value) { "#{field} eq '#{value}'" }, contains: ->(field, value) { "contains(#{field} '#{value}')" } }.freeze
Instance Method Summary collapse
Instance Method Details
#filterable(field, type) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/enotas_api/support/filterable.rb', line 15 def filterable(field, type) handler = FILTER_HANDLERS[type] raise EnotasApi::Error, "Undefined filter type '#{type}', valid values are #{FILTER_HANDLERS.keys}" unless handler define_method "#{field}_#{type}" do |value| param(:filter, handler.call(field, value)) end end |