Class: Hanami::Helpers::FormHelper::Values Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/helpers/form_helper/values.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.

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

Constant Summary collapse

GET_SEPARATOR =

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.

Since:

  • 0.2.0

'.'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(values, params) ⇒ Values

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 Values.

Since:

  • 0.2.0


20
21
22
23
# File 'lib/hanami/helpers/form_helper/values.rb', line 20

def initialize(values, params)
  @values = Utils::Hash.new(values || {}).symbolize!
  @params = params
end

Instance Method Details

#_get_from_params(*keys) ⇒ Object (private)

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.

Since:

  • 0.5.0


38
39
40
# File 'lib/hanami/helpers/form_helper/values.rb', line 38

def _get_from_params(*keys)
  @params.dig(*keys)
end

#_get_from_values(*keys) ⇒ Object (private)

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.

Since:

  • 0.2.0


44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/hanami/helpers/form_helper/values.rb', line 44

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

#get(*keys) ⇒ 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.

Returns the value (if present) for the given key. Nested values are expressed with an array if symbols.

Since:

  • 0.2.0


30
31
32
# File 'lib/hanami/helpers/form_helper/values.rb', line 30

def get(*keys)
  _get_from_params(*keys) || _get_from_values(*keys)
end