solnic / virtus

[DISCONTINUED ] Attributes on Steroids for Plain Old Ruby Objects
MIT License
3.77k stars 229 forks source link

Automatic Accessors - Do We Want That? #179

Closed apotonick closed 11 years ago

apotonick commented 11 years ago

I was wondering if it is Virtus' job to create accessors for the model. I'd love to see the following basic behaviour for a setter (same applies to getter).

def name=(v)
  super coerce(v)
end

Here, virtus just coerces and then delegates responsibility for storing that attribute to the model.

Virtus could provide an additional module (per default) that adds setting and getting accessors to the model as it does now. But that should be optional!

solnic commented 11 years ago

Yes we want that. If you just need coercion then use coercible gem.

apotonick commented 11 years ago

Well I wanna take advantage of the brillant virtus API without having to fiddle with the coercible internals, which might change, etc. I just don't wanna virtus to override my constructor and acessors automatically. Right now, we use a separate coercion object in representable/roar/reform but it would be awesome if I could just include Virtus::Coercion and get the upper behaviour.

solnic commented 11 years ago

Coercers will be exposed in virtus 1.0.0 w/o the need to build attribute instances. I guess that's what you need.