Class: Admino::Query::Base

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



20
21
22
# File 'lib/admino/query/base.rb', line 20

def context
  @context
end

#filter_groupsObject (readonly)

Returns the value of attribute filter_groups.



21
22
23
# File 'lib/admino/query/base.rb', line 21

def filter_groups
  @filter_groups
end

#paramsObject (readonly)

Returns the value of attribute params.



19
20
21
# File 'lib/admino/query/base.rb', line 19

def params
  @params
end

#search_fieldsObject (readonly)

Returns the value of attribute search_fields.



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

def search_fields
  @search_fields
end

#sortingObject (readonly)

Returns the value of attribute sorting.



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

def sorting
  @sorting
end

Class Method Details

.i18n_scopeObject



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

def self.i18n_scope
  :query
end

Instance Method Details

#configObject



64
65
66
# File 'lib/admino/query/base.rb', line 64

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

#filter_group_by_name(name) ⇒ Object



72
73
74
# File 'lib/admino/query/base.rb', line 72

def filter_group_by_name(name)
  @filter_groups[name]
end

#persisted?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/admino/query/base.rb', line 60

def persisted?
  false
end

#scope(starting_scope = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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) ⇒ Object



80
81
82
# File 'lib/admino/query/base.rb', line 80

def search_field_by_name(name)
  @search_fields[name]
end