Class: Munificent::DonatorBundle
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Munificent::DonatorBundle
- Defined in:
- app/models/munificent/donator_bundle.rb
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from ApplicationRecord
Class Method Details
.build_from(bundle, **attrs) ⇒ Object
9 10 11 12 13 14 15 |
# File 'app/models/munificent/donator_bundle.rb', line 9 def self.build_from(bundle, **attrs) new(bundle:, **attrs).tap do |donator_bundle| bundle.bundle_tiers.each do |bundle_tier| donator_bundle.donator_bundle_tiers.build(bundle_tier:) end end end |
.create_from ⇒ Object
17 18 19 |
# File 'app/models/munificent/donator_bundle.rb', line 17 def self.create_from(...) build_from(...).tap(&:save!) end |
Instance Method Details
#complete? ⇒ Boolean
21 22 23 |
# File 'app/models/munificent/donator_bundle.rb', line 21 def complete? locked_tiers.none? end |
#next_unlockable_tier ⇒ Object
25 26 27 |
# File 'app/models/munificent/donator_bundle.rb', line 25 def next_unlockable_tier unlockable_tiers.first end |
#unlockable_tiers_at_or_below(amount) ⇒ Object
29 30 31 |
# File 'app/models/munificent/donator_bundle.rb', line 29 def unlockable_tiers_at_or_below(amount) unlockable_tiers.where("price_decimals <= ?", amount.fractional) end |