Class: Admino::Query::Base
- Inherits:
-
Object
- Object
- Admino::Query::Base
- Extended by:
- ActiveModel::Naming, ActiveModel::Translation, Dsl
- 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.
24 25 26 27 28 29 30 31 |
# File 'lib/admino/query/base.rb', line 24 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.
16 17 18 |
# File 'lib/admino/query/base.rb', line 16 def filter_groups @filter_groups end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
15 16 17 |
# File 'lib/admino/query/base.rb', line 15 def params @params end |
#search_fields ⇒ Object (readonly)
Returns the value of attribute search_fields.
17 18 19 |
# File 'lib/admino/query/base.rb', line 17 def search_fields @search_fields end |
#sorting ⇒ Object (readonly)
Returns the value of attribute sorting.
18 19 20 |
# File 'lib/admino/query/base.rb', line 18 def sorting @sorting end |
Class Method Details
.i18n_scope ⇒ Object
20 21 22 |
# File 'lib/admino/query/base.rb', line 20 def self.i18n_scope :query end |
Instance Method Details
#config ⇒ Object
60 61 62 |
# File 'lib/admino/query/base.rb', line 60 def config @config || self.class.config end |
#filter_group_by_name(name) ⇒ Object
68 69 70 |
# File 'lib/admino/query/base.rb', line 68 def filter_group_by_name(name) @filter_groups[name] end |
#persisted? ⇒ Boolean
56 57 58 |
# File 'lib/admino/query/base.rb', line 56 def persisted? false end |
#scope(starting_scope = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/admino/query/base.rb', line 33 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_builder = starting_scope scope_augmenters = search_fields + filter_groups scope_augmenters << sorting if sorting scope_augmenters.each do |search_field| scope_builder = search_field.augment_scope(scope_builder) end if config.ending_scope_callable scope_builder.instance_exec(self, &config.ending_scope_callable) else scope_builder end end |
#search_field_by_name(name) ⇒ Object
76 77 78 |
# File 'lib/admino/query/base.rb', line 76 def search_field_by_name(name) @search_fields[name] end |