Class: ActiveadminSettingsCached::Coercions Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Coerce user input values to defined types

Constant Summary collapse

TRUE_VALUES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%w[1 on On ON t true True TRUE T y yes Yes YES Y].freeze
FALSE_VALUES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%w[0 off Off OFF f false False FALSE F n no No NO N].freeze
BOOLEAN_MAP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

::Hash[
  TRUE_VALUES.product([true]) + FALSE_VALUES.product([false])
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(defaults, display) ⇒ Coercions

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Coercions.



16
17
18
19
# File 'lib/activeadmin_settings_cached/coercions.rb', line 16

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

Instance Attribute Details

#defaultsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
# File 'lib/activeadmin_settings_cached/coercions.rb', line 14

def defaults
  @defaults
end

#displayObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
# File 'lib/activeadmin_settings_cached/coercions.rb', line 14

def display
  @display
end

Instance Method Details

#cast_params(params) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/activeadmin_settings_cached/coercions.rb', line 21

def cast_params(params)
  coerced_params = params.to_unsafe_h.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) unless value.nil?
  end
end