G5 / storext

Add type-casting and other features on top of ActiveRecord::Store.store_accessor

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support namespace

radubogdan opened this issue · comments

Hello guys,

It might be a weird need but is there a plan/are you willing to accept a PR that introduce a namespace/scope/prefix concept around the stored attributes when there is a need for identical name?

I'm thinking at:

class Car
  include Storext.model

  store_attributes :financing_offer, namespace: :financing do
    monthly_payment Float
    ....
  end

  store_attributes :leasing_offer, namespace: :leasing do
    monthly_payment Float
    ....
  end
end

Which will define monthly_payment accessor with a prefix so that there is no clash between attributes with same name.

car.leasing_monthly_payment => 0.11
car.financing_monthly_payment => 0.22
car.monthly_payment => NoMethodError: undefined method `monthly_payment'

Of course you can directly choose a different name but I'm wondering if it can be something beneficial at some point :)

@radubogdan no discussion around this yet I think. If I understand right, this would yield what you want but in a more verbose manner, right?

class Car
  include Storext.model

  store_attributes :financing_offer do
    financing_monthly_payment Float
    ....
  end

  store_attributes :leasing_offer do
    leasing_monthly_payment Float
    ....
  end
end

I'm inclined to just use the method above; this way you can have other attributes where you do not need a prefix. Yes, it's more verbose, but there's also more control without much more work.

Thank you for the reply and for clarifying this @ramontayag. If there is no future plan of reducing verbosity then I suggest we close this.