Class: ActiveadminSettingsCached::Coercions

Inherits:
Object
  • Object
show all
Defined in:
lib/activeadmin_settings_cached/coercions.rb

Constant Summary collapse

SIMPLE_COERCIONS =
{
  float: :to_f,
  integer: :to_i,
  symbol: :to_sym
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(defaults, display) ⇒ Coercions

Returns a new instance of Coercions.



10
11
12
13
14
15
# File 'lib/activeadmin_settings_cached/coercions.rb', line 10

def initialize(defaults, display)
  @defaults = defaults
  @display = display

  init_methods
end

Instance Attribute Details

#defaultsObject (readonly)

Returns the value of attribute defaults.



8
9
10
# File 'lib/activeadmin_settings_cached/coercions.rb', line 8

def defaults
  @defaults
end

#displayObject (readonly)

Returns the value of attribute display.



8
9
10
# File 'lib/activeadmin_settings_cached/coercions.rb', line 8

def display
  @display
end

Instance Method Details

#cast_params(params) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/activeadmin_settings_cached/coercions.rb', line 17

def cast_params(params)
  coerced_params = params.map do |name, value|
    [name, cast_value(name, value)]
  end

  return coerced_params unless block_given?

  coerced_params.each do |name, value|
    yield(name, value.call)
  end
end