hanami / model

Ruby persistence framework with entities and repositories

Home Page:http://hanamirb.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#to_hash and implicit conversion

antstorm opened this issue · comments

Something that caught me off guard when using an instance of Hanami::Entity with Ruby's double splat:

class User < Hanami::Entity
  attributes do
    attribute :id,   Types::Int
    attribute :name, Types::String
  end
end

def test_me(user = nil, **options)
  puts "user: #{user}"
  puts "options: #{options}"
end

> test_me(User.new(id: 42, name: 'Tester'))
user:
options: {:id=>:42,:name=>'Tester'}

Due to implicit conversion (#to_hash) User instance gets deconstructed into a hash when passed into the test method. The behaviour was introduce in this PR — 26c17eb.

My question is — was it intentional and there's a legit use-case or accidental?

This will be addressed in Hanami 2.0. This method will be gone as it has confusing behaviors like you noticed.

This is great, thank you, @solnic!

Do you have a timeline in mind for Hanami 2.0? I know things have been a bit stale recently

@antstorm we'll be posting an official roadmap/timeline very soon! I recommend following Tim's updates on his blog too. You can also see our Trello board to get a sense of where we are in the process.

@solnic ah, lovely, great to see there's some progress on the project. I really enjoy Hanami and have been running it in production for 1.5 years now