Class: Admino::Query::SearchField
- Inherits:
-
Object
- Object
- Admino::Query::SearchField
- Defined in:
- lib/admino/query/search_field.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
- #augment_scope(scope) ⇒ Object
-
#initialize(config, params) ⇒ SearchField
constructor
A new instance of SearchField.
- #param_name ⇒ Object
- #present? ⇒ Boolean
- #scope_name ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(config, params) ⇒ SearchField
Returns a new instance of SearchField.
11 12 13 14 |
# File 'lib/admino/query/search_field.rb', line 11 def initialize(config, params) @config = config @params = ActiveSupport::HashWithIndifferentAccess.new(params) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
9 10 11 |
# File 'lib/admino/query/search_field.rb', line 9 def config @config end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
8 9 10 |
# File 'lib/admino/query/search_field.rb', line 8 def params @params end |
Instance Method Details
#augment_scope(scope) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/admino/query/search_field.rb', line 16 def augment_scope(scope) if present? scope.send(scope_name, value) else scope end end |
#param_name ⇒ Object
43 44 45 |
# File 'lib/admino/query/search_field.rb', line 43 def param_name config.name end |
#present? ⇒ Boolean
39 40 41 |
# File 'lib/admino/query/search_field.rb', line 39 def present? value.present? end |
#scope_name ⇒ Object
47 48 49 |
# File 'lib/admino/query/search_field.rb', line 47 def scope_name config.name end |
#value ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/admino/query/search_field.rb', line 24 def value value = params.fetch(:query, {}).fetch(param_name, nil) if config.coerce_to value = begin coercer = Coercible::Coercer.new coercer[value.class].send(config.coerce_to, value) rescue Coercible::UnsupportedCoercion nil end end value || config.default_value end |