madeintandem / hstore_accessor

Adds typed hstore-backed field support to ActiveRecord models.
MIT License
242 stars 47 forks source link

Add ability to extend getters and setters via calls to super #21

Closed crismali closed 10 years ago

crismali commented 10 years ago

You can extend the getters and setters like this now:

class Product
  hstore_accessor :options, {
    color: :string
  }

  def color=(value)
    super(value.upcase)
  end

  def color
    super.downcase
  end
end
jaimerson commented 10 years ago

:+1:

thegrubbsian commented 10 years ago

I generally don't think overriding getters and setters is a good idea, but, because ActiveRecord already supports this for native (non-hstore) fields I think we can do it here. However, you should probably consider the need for the use of super in a setter to be a smell.

andreorvalho commented 10 years ago

@thegrubbsian you are probably right, but in the case of an array that comes with the empty element already from default rails behaviour, what would be the proposal to fix that?