Class: Admino::Query::Base
- Inherits:
-
Object
- Object
- Admino::Query::Base
- Extended by:
- ActiveModel::Naming, ActiveModel::Translation, Dsl
- Includes:
- ActiveModel::Conversion
- Defined in:
- lib/admino/query/base.rb
Instance Attribute Summary collapse
-
#filter_groups ⇒ Object
readonly
Returns the value of attribute filter_groups.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#search_fields ⇒ Object
readonly
Returns the value of attribute search_fields.
-
#sorting ⇒ Object
readonly
Returns the value of attribute sorting.
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
- #filter_group_by_name(name) ⇒ Object
-
#initialize(params = nil, config = nil) ⇒ Base
constructor
A new instance of Base.
- #persisted? ⇒ Boolean
- #scope(starting_scope = nil) ⇒ Object
- #search_field_by_name(name) ⇒ Object
Methods included from Dsl
ending_scope, filter_by, search_field, starting_scope
Constructor Details
#initialize(params = nil, config = nil) ⇒ Base
Returns a new instance of Base.
28 29 30 31 32 33 34 35 |
# File 'lib/admino/query/base.rb', line 28 def initialize(params = nil, config = nil) @params = ActiveSupport::HashWithIndifferentAccess.new(params) @config = config init_filter_groups init_search_fields init_sorting end |
Instance Attribute Details
#filter_groups ⇒ Object (readonly)
Returns the value of attribute filter_groups.
20 21 22 |
# File 'lib/admino/query/base.rb', line 20 def filter_groups @filter_groups end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
19 20 21 |
# File 'lib/admino/query/base.rb', line 19 def params @params end |
#search_fields ⇒ Object (readonly)
Returns the value of attribute search_fields.
21 22 23 |
# File 'lib/admino/query/base.rb', line 21 def search_fields @search_fields end |
#sorting ⇒ Object (readonly)
Returns the value of attribute sorting.
22 23 24 |
# File 'lib/admino/query/base.rb', line 22 def sorting @sorting end |
Class Method Details
.i18n_scope ⇒ Object
24 25 26 |
# File 'lib/admino/query/base.rb', line 24 def self.i18n_scope :query end |
Instance Method Details
#config ⇒ Object
57 58 59 |
# File 'lib/admino/query/base.rb', line 57 def config @config || self.class.config end |
#filter_group_by_name(name) ⇒ Object
65 66 67 |
# File 'lib/admino/query/base.rb', line 65 def filter_group_by_name(name) @filter_groups[name] end |
#persisted? ⇒ Boolean
53 54 55 |
# File 'lib/admino/query/base.rb', line 53 def persisted? false end |
#scope(starting_scope = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/admino/query/base.rb', line 37 def scope(starting_scope = nil) starting_scope ||= if config.starting_scope_callable config.starting_scope_callable.call(self) else raise ArgumentError, 'no starting scope provided' end scope = augment_scope(Builder.new(self, starting_scope)).scope if config.ending_scope_callable scope.instance_exec(self, &config.ending_scope_callable) else scope end end |
#search_field_by_name(name) ⇒ Object
73 74 75 |
# File 'lib/admino/query/base.rb', line 73 def search_field_by_name(name) @search_fields[name] end |