class Hanami::Helpers::FormHelper::Values
Values
from params and form helpers.
It's responsible to populate input values with data coming from params and inline values specified via form helpers like `text_field`.
@since 0.2.0 @api private
Constants
- GET_SEPARATOR
@since 0.2.0 @api private
Public Class Methods
new(values, params)
click to toggle source
@since 0.2.0 @api private
# File lib/hanami/helpers/form_helper/values.rb, line 20 def initialize(values, params) @values = Utils::Hash.symbolize(values || {}) @params = params end
Public Instance Methods
get(*keys)
click to toggle source
Returns the value (if present) for the given key. Nested values are expressed with an array if symbols.
@since 0.2.0 @api private
# File lib/hanami/helpers/form_helper/values.rb, line 30 def get(*keys) _get_from_params(*keys) || _get_from_values(*keys) end
Private Instance Methods
_dig(base, key)
click to toggle source
@since 1.0.0 @api private
# File lib/hanami/helpers/form_helper/values.rb, line 60 def _dig(base, key) case base when Utils::Hash, ::Hash then base[key] when Array then base[key.to_s.to_i] when ->(r) { r.respond_to?(key) } then base.public_send(key) end end
_get_from_params(*keys)
click to toggle source
@since 0.5.0 @api private
# File lib/hanami/helpers/form_helper/values.rb, line 38 def _get_from_params(*keys) keys.map! { |key| key.to_s =~ /\A\d+\z/ ? key.to_s.to_i : key } @params.dig(*keys) end
_get_from_values(*keys)
click to toggle source
@since 0.2.0 @api private
# File lib/hanami/helpers/form_helper/values.rb, line 45 def _get_from_values(*keys) head, *tail = *keys result = @values[head] tail.each do |k| break if result.nil? result = _dig(result, k) end result end