Sha256: 424fd90966e82801ccb2371916eef385d3c46d7fc0918b22c6661b7281eb6b7c
Contents?: true
Size: 1.45 KB
Versions: 1
Compression:
Stored size: 1.45 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) @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 = if result.respond_to?(k) # rubocop:disable Style/IfUnlessModifier result.public_send(k) end end result end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
hanami-helpers-0.5.0 | lib/hanami/helpers/form_helper/values.rb |