Class: BillerBotResource::Product
- Defined in:
- lib/biller_bot_resource/product.rb
Defined Under Namespace
Classes: Context
Instance Method Summary collapse
- #all_contexts ⇒ Object
- #context(id) ⇒ Object
- #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.
64 65 66 67 68 69 70 |
# File 'lib/biller_bot_resource/product.rb', line 64 def initialize(*args) super contexts.each do |c| c.product = self c.force_persisted # See comments on method end end |
Instance Method Details
#all_contexts ⇒ Object
77 78 79 |
# File 'lib/biller_bot_resource/product.rb', line 77 def all_contexts contexts.map(&:descendants_with_self).flatten end |
#context(id) ⇒ Object
81 82 83 84 85 |
# File 'lib/biller_bot_resource/product.rb', line 81 def context(id) context = all_contexts.select { |c| c.id.try(:to_i) == id.to_i }.first raise ActiveResource::ResourceNotFound.new(nil) if context.nil? context end |
#contexts ⇒ Object
72 73 74 75 |
# File 'lib/biller_bot_resource/product.rb', line 72 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.
92 93 94 |
# File 'lib/biller_bot_resource/product.rb', line 92 def root_context_for_account_id(account_id) contexts.select { |c| c.type == "AccountProductContext" && c.account_id == account_id }.first end |