Class: GestartAdmino::Query::Base
- Inherits:
-
Object
- Object
- GestartAdmino::Query::Base
- Extended by:
- ActiveModel::Naming, ActiveModel::Translation, Dsl
- Includes:
- ActiveModel::Conversion
- Defined in:
- lib/gestart_admino/query/base.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#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, context = {}, 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, context = {}, config = nil) ⇒ Base
Returns a new instance of Base.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/gestart_admino/query/base.rb', line 30 def initialize(params = nil, context = {}, config = nil) @params = if params.respond_to?(:to_unsafe_h) ActiveSupport::HashWithIndifferentAccess.new(params.to_unsafe_h) else ActiveSupport::HashWithIndifferentAccess.new(params) end @config = config @context = context init_filter_groups init_search_fields init_sorting end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
21 22 23 |
# File 'lib/gestart_admino/query/base.rb', line 21 def context @context end |
#filter_groups ⇒ Object (readonly)
Returns the value of attribute filter_groups.
22 23 24 |
# File 'lib/gestart_admino/query/base.rb', line 22 def filter_groups @filter_groups end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
20 21 22 |
# File 'lib/gestart_admino/query/base.rb', line 20 def params @params end |
#search_fields ⇒ Object (readonly)
Returns the value of attribute search_fields.
23 24 25 |
# File 'lib/gestart_admino/query/base.rb', line 23 def search_fields @search_fields end |
#sorting ⇒ Object (readonly)
Returns the value of attribute sorting.
24 25 26 |
# File 'lib/gestart_admino/query/base.rb', line 24 def sorting @sorting end |
Class Method Details
.i18n_scope ⇒ Object
26 27 28 |
# File 'lib/gestart_admino/query/base.rb', line 26 def self.i18n_scope :query end |
Instance Method Details
#config ⇒ Object
65 66 67 |
# File 'lib/gestart_admino/query/base.rb', line 65 def config @config || self.class.config end |
#filter_group_by_name(name) ⇒ Object
73 74 75 |
# File 'lib/gestart_admino/query/base.rb', line 73 def filter_group_by_name(name) @filter_groups[name] end |
#persisted? ⇒ Boolean
61 62 63 |
# File 'lib/gestart_admino/query/base.rb', line 61 def persisted? false end |
#scope(starting_scope = nil) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/gestart_admino/query/base.rb', line 45 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
81 82 83 |
# File 'lib/gestart_admino/query/base.rb', line 81 def search_field_by_name(name) @search_fields[name] end |