Class: GestartAdmino::Query::Base

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming, ActiveModel::Translation, Dsl
Includes:
ActiveModel::Conversion
Defined in:
lib/gestart_admino/query/base.rb

Constant Summary collapse

TOP_LEVEL_PARAMS =
%i[page sorting sort_order].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Dsl

ending_scope, filter_by, permit_params, search_field, starting_scope

Constructor Details

#initialize(params = nil, context = {}, config = nil) ⇒ Base

Returns a new instance of Base.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gestart_admino/query/base.rb', line 32

def initialize(params = nil, context = {}, config = nil)
  @config = config
  @context = context

  raw =
    if params.respond_to?(:to_unsafe_h)
      ActiveSupport::HashWithIndifferentAccess.new(params.to_unsafe_h)
    else
      ActiveSupport::HashWithIndifferentAccess.new(params)
    end
  @params = permitted_params(raw)

  init_filter_groups
  init_search_fields
  init_sorting
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



23
24
25
# File 'lib/gestart_admino/query/base.rb', line 23

def context
  @context
end

#filter_groupsObject (readonly)

Returns the value of attribute filter_groups.



24
25
26
# File 'lib/gestart_admino/query/base.rb', line 24

def filter_groups
  @filter_groups
end

#paramsObject (readonly)

Returns the value of attribute params.



22
23
24
# File 'lib/gestart_admino/query/base.rb', line 22

def params
  @params
end

#search_fieldsObject (readonly)

Returns the value of attribute search_fields.



25
26
27
# File 'lib/gestart_admino/query/base.rb', line 25

def search_fields
  @search_fields
end

#sortingObject (readonly)

Returns the value of attribute sorting.



26
27
28
# File 'lib/gestart_admino/query/base.rb', line 26

def sorting
  @sorting
end

Class Method Details

.i18n_scopeObject



28
29
30
# File 'lib/gestart_admino/query/base.rb', line 28

def self.i18n_scope
  :query
end

Instance Method Details

#configObject



69
70
71
# File 'lib/gestart_admino/query/base.rb', line 69

def config
  @config || self.class.config
end

#filter_group_by_name(name) ⇒ Object



77
78
79
# File 'lib/gestart_admino/query/base.rb', line 77

def filter_group_by_name(name)
  @filter_groups[name]
end

#persisted?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/gestart_admino/query/base.rb', line 65

def persisted?
  false
end

#scope(starting_scope = nil) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gestart_admino/query/base.rb', line 49

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



85
86
87
# File 'lib/gestart_admino/query/base.rb', line 85

def search_field_by_name(name)
  @search_fields[name]
end