Class: Admino::Query::FilterGroup
- Inherits:
-
Object
- Object
- Admino::Query::FilterGroup
- Defined in:
- lib/admino/query/filter_group.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#query_i18n_key ⇒ Object
readonly
Returns the value of attribute query_i18n_key.
Instance Method Summary collapse
- #active_scope ⇒ Object
- #augment_scope(scope) ⇒ Object
- #i18n_key ⇒ Object
-
#initialize(config, params, query_i18n_key = nil) ⇒ FilterGroup
constructor
A new instance of FilterGroup.
- #is_scope_active?(scope) ⇒ Boolean
- #param_name ⇒ Object
- #scopes ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(config, params, query_i18n_key = nil) ⇒ FilterGroup
Returns a new instance of FilterGroup.
11 12 13 14 15 |
# File 'lib/admino/query/filter_group.rb', line 11 def initialize(config, params, query_i18n_key = nil) @config = config @params = ActiveSupport::HashWithIndifferentAccess.new(params) @query_i18n_key = query_i18n_key end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/admino/query/filter_group.rb', line 8 def config @config end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
7 8 9 |
# File 'lib/admino/query/filter_group.rb', line 7 def params @params end |
#query_i18n_key ⇒ Object (readonly)
Returns the value of attribute query_i18n_key.
9 10 11 |
# File 'lib/admino/query/filter_group.rb', line 9 def query_i18n_key @query_i18n_key end |
Instance Method Details
#active_scope ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/admino/query/filter_group.rb', line 25 def active_scope if value && scopes.include?(value.to_sym) value.to_sym else nil end end |
#augment_scope(scope) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/admino/query/filter_group.rb', line 17 def augment_scope(scope) if active_scope && active_scope != :empty scope.send(active_scope) else scope end end |
#i18n_key ⇒ Object
54 55 56 |
# File 'lib/admino/query/filter_group.rb', line 54 def i18n_key config.name end |
#is_scope_active?(scope) ⇒ Boolean
33 34 35 |
# File 'lib/admino/query/filter_group.rb', line 33 def is_scope_active?(scope) active_scope == scope.to_sym end |
#param_name ⇒ Object
42 43 44 |
# File 'lib/admino/query/filter_group.rb', line 42 def param_name config.name end |
#scopes ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/admino/query/filter_group.rb', line 46 def scopes @scopes ||= config.scopes.dup.tap do |scopes| if config.include_empty_scope? scopes.unshift :empty end end end |
#value ⇒ Object
37 38 39 40 |
# File 'lib/admino/query/filter_group.rb', line 37 def value default_value = config.include_empty_scope? ? :empty : nil params.fetch(:query, {}).fetch(param_name, default_value) end |