Module: Susply::OwnerMethods
- Defined in:
- app/services/susply/owner_methods.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #active_subscription ⇒ Object
- #has_active_subscription? ⇒ Boolean
- #most_recently_deactivated_subscription ⇒ Object
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'app/services/susply/owner_methods.rb', line 3 def self.included(base) base.extend ClassMethods base.class_eval do has_many :subscriptions, class_name: 'Susply::Subscription', foreign_key: 'owner_id' has_many :payments, class_name: 'Susply::Payment', foreign_key: 'owner_id' end end |
Instance Method Details
#active_subscription ⇒ Object
20 21 22 |
# File 'app/services/susply/owner_methods.rb', line 20 def active_subscription subscriptions.detect(&:active?) end |
#has_active_subscription? ⇒ Boolean
16 17 18 |
# File 'app/services/susply/owner_methods.rb', line 16 def has_active_subscription? active_subscription.present? end |
#most_recently_deactivated_subscription ⇒ Object
24 25 26 |
# File 'app/services/susply/owner_methods.rb', line 24 def most_recently_deactivated_subscription subscriptions.reject(&:active?).max_by(&:deactivated_at) end |