Module: Subly::InstanceMethods

Defined in:
lib/subly.rb

Instance Method Summary collapse

Instance Method Details

#add_subscription(name, args = {}) ⇒ Object



40
41
42
43
44
# File 'lib/subly.rb', line 40

def add_subscription(name, args = {})
  args[:starts_at] ||=  Time.now
  args[:name] = name
  self.sublies.create(args)
end

#cancel_active_subscriptions(name) ⇒ Object



54
55
56
# File 'lib/subly.rb', line 54

def cancel_active_subscriptions(name)
  self.sublies.active.by_name(name).collect(&:expire_now)
end

#cancel_all_subscriptions(name) ⇒ Object



58
59
60
61
62
63
# File 'lib/subly.rb', line 58

def cancel_all_subscriptions(name)
  self.sublies.unexpired.by_name(name).each do |sub|
    #if active, deactivate, else destroy as and end_time greater than start is not valid
    sub.active? ? sub.expire_now : sub.destroy
  end
end

#has_active_subscription?(name) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/subly.rb', line 50

def has_active_subscription?(name)
  self.sublies.active.by_name(name).count > 0
end

#has_subscription?(name) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/subly.rb', line 46

def has_subscription?(name)
  self.sublies.by_name(name).count > 0
end