Sha256: a54f13f004464096c1d0ed0205d0f481f010ff9a413b56a0d69892e2360a1499
Contents?: true
Size: 1.72 KB
Versions: 3
Compression:
Stored size: 1.72 KB
Contents
require 'hanami/utils/hash' module Hanami module Helpers module FormHelper # 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 class Values # @since 0.2.0 # @api private GET_SEPARATOR = '.'.freeze # @since 0.2.0 # @api private def initialize(values, params) @values = Utils::Hash.new(values || {}).symbolize! @params = params end # Returns the value (if present) for the given key. # Nested values are expressed with an array if symbols. # # @since 0.2.0 # @api private def get(*keys) _get_from_params(*keys) || _get_from_values(*keys) end private # @since 0.5.0 # @api private def _get_from_params(*keys) keys.map! { |key| key.to_s =~ /\A\d+\z/ ? key.to_s.to_i : key } @params.dig(*keys) end # @since 0.2.0 # @api private 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 # @since 1.0.0.beta1 # @api private 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 end end end end
Version data entries
3 entries across 3 versions & 1 rubygems