Support deep coercion for Hash attributes #98

Closed
postmodern opened this Issue Jun 25, 2012 · 6 comments

Projects

None yet

5 participants

@postmodern

Virtus should support deep coercion of Hash attributes.

Example Code

attribute :settings, Hash[Symbol => Float]
# ...
user.settings = params[:settings]
@dkubb
Collaborator
dkubb commented Jun 28, 2012

That's interesting. I guess it fits in with Array[Something] format that we support now.

@greyblake

I'm working on it.

@solnic
Owner
solnic commented Sep 1, 2012

@greyblake that's awesome!

@greyblake greyblake added a commit to greyblake/virtus that referenced this issue Sep 1, 2012
@greyblake greyblake Support deep coercion for Hash attributes
Issue #98
5ab13ce
@greyblake greyblake added a commit to greyblake/virtus that referenced this issue Sep 1, 2012
@greyblake greyblake Update comment of Virtus::Attribute::Hash#new_hash
Issue #98
17a6240
@greyblake greyblake added a commit to greyblake/virtus that referenced this issue Sep 2, 2012
@greyblake greyblake Remove pry
Issue #98
05bd947
@greyblake greyblake added a commit to greyblake/virtus that referenced this issue Sep 2, 2012
@greyblake greyblake Add Hash attributes coercon example to README
Issue #98
47474ed
@greyblake greyblake added a commit to greyblake/virtus that referenced this issue Sep 2, 2012
@greyblake greyblake Rename hash_member_coercion_spec.rb -> hash_attributes_coercion_spec.rb
Issue #98
c9e592f
@greyblake greyblake added a commit to greyblake/virtus that referenced this issue Sep 2, 2012
@greyblake greyblake remove extra line
Issue #98
0242d1c
@greyblake greyblake added a commit to greyblake/virtus that referenced this issue Sep 2, 2012
@greyblake greyblake use each_object_with instead of inject
Issue #98
68793d2
@greyblake greyblake added a commit to greyblake/virtus that referenced this issue Sep 15, 2012
@greyblake greyblake Do not redefined Hash#[]= method
Issue #112
Issue #98
01922f8
@solnic
Owner
solnic commented Oct 1, 2012

This is done now. It'll be available in the next release.

@solnic solnic closed this Oct 1, 2012
@postmodern

Awesome!

@ka8725
ka8725 commented Jun 27, 2014

We solved this issues defining custom collection:

class VirtusCollection < Array
  def to_hash
      map(&:to_hash)
  end
end

Is it correct code or is there standard implementation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment