Skip to content

Commit

Permalink
Prepare for v0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jodosha committed Nov 10, 2016
1 parent e19ad89 commit c770e54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 33 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,16 @@
# Hanami::Helpers
View helpers for Ruby web applications

## v0.5.0 - (unreleased)
### Added
- [Marion Duprey] Allow `select` form helper to generate a multiple select (via `multiple: true` option)

### Fixed
- [Luca Guidi] Ensure `form_for` to be compatible with params passed as `Hash`. This is useful for unit tests.

### Changed
- [Luca Guidi] Official support for Ruby: MRI 2.3+ and JRuby 9.1.5.0+

## v0.4.0 - 2016-07-22
### Added
- [Luca Guidi] Allow `link_to` to be concat with other helpers. Eg `link_to(...) + link_to(...)`, `span(...) + link_to(...)`.
Expand Down
36 changes: 3 additions & 33 deletions lib/hanami/helpers/form_helper/values.rb
Expand Up @@ -22,7 +22,8 @@ def initialize(values, params)
@params = params
end

# Returns the value for the given key, if present
# Returns the value (if present) for the given key.
# Nested values are expressed with an array if symbols.
#
# @since 0.2.0
# @api private
Expand All @@ -32,38 +33,7 @@ def get(*keys)

private

# Safely access nested values.
#
# <tt>Hanami::Action::Params</tt> already supports this feature with
# <tt>#get</tt>.
# But during testing phase it could happen to receive a <tt>Hash</tt>
# instead.
#
# For this purpose, we check if <tt>@params</tt> respond to
# <tt>#dig</tt>, which is a new Ruby 2.3 feature similar to
# <tt>Hanami::Action::Params#get</tt>.
# If the check is successful, we try to access the value with
# <tt>#dig</tt>, otherwise we assume that it responds to <tt>#get</tt>
# and use it.
#
# This implementation is safe to use, but it has several hidden perf costs:
#
# * The runtime check for <tt>#respond_to?</tt>, which is inelegant too
# * In case of <tt>#dig</tt> we need to transform a key like
# <tt>:'order.customer.address.street'</tt> into
# <tt>[:order, :customer, :address, :street]</tt>
# * In case of <tt>#get</tt> its internal implementation isn't
# efficient because it splits the key into an array and it uses
# recursion to access nested values
#
# Because as of Ruby 2.3 we have <tt>Hash#dig</tt>, we should use it
# both in params and here, because it's faster (written in C).
# To make this possible, we should change the key notation from a dot
# separated string to an array of symbol.
#
# FIXME: Use Hash#dig when we'll support only Ruby 2.3+
#
# @since x.x.x
# @since 0.5.0
# @api private
def _get_from_params(*keys)
@params.dig(*keys)
Expand Down

0 comments on commit c770e54

Please sign in to comment.