solnic / virtus

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

alias substitute #353

Closed jbodah closed 8 years ago

jbodah commented 8 years ago

It would be nice to have some substitute for the alias keyword. In the example below let's assume I have two Virtus modules each used in many places (e.g. it's hard to just rename a field). It would be awesome in the short term to just be able add alias :id :google_id allowing me to just duck-type on id in my generic code, but Virtus maintains an internal variable for attributes which means alias doesn't work properly since we never define that method

module GoogleMetadata
  include Virtus.module

  attribute :google_id
end

module GenericMetadata
  include Virtus.module

  attribute :id
end

class GenericProcessor
  def process(object)
    # log(object.id)
  end
end
booch commented 8 years ago

Can you expand on that a bit? I'm not quite following what you're asking for.

Would you be able to just define a method instead? Like:

module GenericMetadata
  include Virtus.module

  attribute :id

  def google_id
    id
  end
end
jbodah commented 8 years ago

Yeah this is the solution we wound up going with