Class: GestartAdmino::Query::SearchField

Inherits:
Object
  • Object
show all
Defined in:
lib/gestart_admino/query/search_field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, params) ⇒ SearchField

Returns a new instance of SearchField.



10
11
12
13
# File 'lib/gestart_admino/query/search_field.rb', line 10

def initialize(config, params)
  @config = config
  @params = ActiveSupport::HashWithIndifferentAccess.new(params)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/gestart_admino/query/search_field.rb', line 8

def config
  @config
end

#paramsObject (readonly)

Returns the value of attribute params.



7
8
9
# File 'lib/gestart_admino/query/search_field.rb', line 7

def params
  @params
end

Instance Method Details

#augment_scope(scope) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/gestart_admino/query/search_field.rb', line 15

def augment_scope(scope)
  if present?
    scope.send(scope_name, value)
  else
    scope
  end
end

#param_nameObject



33
34
35
# File 'lib/gestart_admino/query/search_field.rb', line 33

def param_name
  config.name
end

#present?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/gestart_admino/query/search_field.rb', line 29

def present?
  value.present?
end

#scope_nameObject



37
38
39
# File 'lib/gestart_admino/query/search_field.rb', line 37

def scope_name
  config.name
end

#valueObject



23
24
25
26
27
# File 'lib/gestart_admino/query/search_field.rb', line 23

def value
  value = params.fetch(:query, {}).fetch(param_name, nil)

  value || config.default_value
end