class Admino::Query::Base
Attributes
context[R]
filter_groups[R]
params[R]
search_fields[R]
sorting[R]
Public Class Methods
i18n_scope()
click to toggle source
# File lib/admino/query/base.rb, line 25 def self.i18n_scope :query end
new(params = nil, context = {}, config = nil)
click to toggle source
# File lib/admino/query/base.rb, line 29 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
Public Instance Methods
config()
click to toggle source
# File lib/admino/query/base.rb, line 64 def config @config || self.class.config end
filter_group_by_name(name)
click to toggle source
# File lib/admino/query/base.rb, line 72 def filter_group_by_name(name) @filter_groups[name] end
persisted?()
click to toggle source
# File lib/admino/query/base.rb, line 60 def persisted? false end
scope(starting_scope = nil)
click to toggle source
# File lib/admino/query/base.rb, line 44 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)
click to toggle source
# File lib/admino/query/base.rb, line 80 def search_field_by_name(name) @search_fields[name] end
Private Instance Methods
augment_scope(query_builder)
click to toggle source
# File lib/admino/query/base.rb, line 86 def augment_scope(query_builder) scope_augmenters.each do |augmenter| query_builder = augmenter.augment_scope(query_builder) end query_builder end
init_filter_groups()
click to toggle source
# File lib/admino/query/base.rb, line 100 def init_filter_groups @filter_groups = {} i18n_key = self.class.model_name.i18n_key config.filter_groups.each do |config| @filter_groups[config.name] = FilterGroup.new(config, params, i18n_key) end end
init_search_fields()
click to toggle source
# File lib/admino/query/base.rb, line 108 def init_search_fields @search_fields = {} config.search_fields.each do |config| @search_fields[config.name] = SearchField.new(config, params) end end
init_sorting()
click to toggle source
# File lib/admino/query/base.rb, line 115 def init_sorting if config.sorting i18n_key = self.class.model_name.i18n_key @sorting = Sorting.new(config.sorting, params, i18n_key) end end
scope_augmenters()
click to toggle source
# File lib/admino/query/base.rb, line 94 def scope_augmenters scope_augmenters = search_fields + filter_groups scope_augmenters << sorting if sorting scope_augmenters end