Class: BillerBotResource::Product
- Defined in:
- lib/biller_bot_resource/product.rb
Defined Under Namespace
Classes: Context
Instance Method Summary collapse
- #contexts ⇒ Object
-
#initialize(*args) ⇒ Product
constructor
A new instance of Product.
-
#root_context_for_account_id(account_id) ⇒ BillerBotResource::ProductContext|nil
Fetch the root product context for the given account ID.
Methods inherited from Resource
#cache_key, config, configure, instantiate_collection, query_string, #save
Constructor Details
#initialize(*args) ⇒ Product
Returns a new instance of Product.
21 22 23 24 25 26 27 |
# File 'lib/biller_bot_resource/product.rb', line 21 def initialize(*args) super contexts.each do |c| c.product_id = id c.force_persisted # See comments on method end end |
Instance Method Details
#contexts ⇒ Object
29 30 31 32 |
# File 'lib/biller_bot_resource/product.rb', line 29 def contexts @attributes[:contexts] ||= [] @attributes[:contexts] end |
#root_context_for_account_id(account_id) ⇒ BillerBotResource::ProductContext|nil
Fetch the root product context for the given account ID.
39 40 41 |
# File 'lib/biller_bot_resource/product.rb', line 39 def root_context_for_account_id(account_id) contexts.select { |c| c.type == "AccountProductContext" && c.account_id == account_id }.first end |