Class: Subly::Model
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Subly::Model
- Defined in:
- lib/subly/model.rb
Class Method Summary collapse
- .active ⇒ Object
- .by_name(name) ⇒ Object
- .expired ⇒ Object
- .for_subscriber(sub) ⇒ Object
- .unexpired ⇒ Object
Instance Method Summary collapse
- #active? ⇒ Boolean
- #duration ⇒ Object
- #duration=(duration) ⇒ Object
- #expire_now ⇒ Object
- #expired? ⇒ Boolean
- #in_the_future? ⇒ Boolean
Class Method Details
.active ⇒ Object
14 15 16 17 |
# File 'lib/subly/model.rb', line 14 def self.active now = Time.zone.now scoped(:conditions => ['starts_at <= ? AND (ends_at > ? OR ends_at IS NULL)', now, now]) end |
.by_name(name) ⇒ Object
34 35 36 |
# File 'lib/subly/model.rb', line 34 def self.by_name(name) scoped(:conditions => {:name => name}) end |
.expired ⇒ Object
19 20 21 22 |
# File 'lib/subly/model.rb', line 19 def self.expired now = Time.zone.now scoped(:conditions => ['starts_at <= ? AND ends_at <= ?', now, now]) end |
.for_subscriber(sub) ⇒ Object
29 30 31 32 |
# File 'lib/subly/model.rb', line 29 def self.for_subscriber(sub) raise ArgumentError('wrong number of arguments (0 for 1)') if sub.blank? scoped(:conditions => ['subscriber_type = ? AND subscriber_id = ?',sub.class.to_s, sub.id]) end |
.unexpired ⇒ Object
24 25 26 27 |
# File 'lib/subly/model.rb', line 24 def self.unexpired now = Time.zone.now scoped(:conditions => ['ends_at > ? OR ends_at IS NULL', now]) end |
Instance Method Details
#active? ⇒ Boolean
46 47 48 49 |
# File 'lib/subly/model.rb', line 46 def active? now = Time.now !!(starts_at <= now && (ends_at.nil? || ends_at > now)) end |
#duration ⇒ Object
42 43 44 |
# File 'lib/subly/model.rb', line 42 def duration @duration end |
#duration=(duration) ⇒ Object
38 39 40 |
# File 'lib/subly/model.rb', line 38 def duration=(duration) @duration = duration end |
#expire_now ⇒ Object
61 62 63 |
# File 'lib/subly/model.rb', line 61 def expire_now self.update_attribute(:ends_at, Time.now) end |
#expired? ⇒ Boolean
51 52 53 54 |
# File 'lib/subly/model.rb', line 51 def expired? now = Time.now !(ends_at.nil? || ends_at > now) end |
#in_the_future? ⇒ Boolean
56 57 58 59 |
# File 'lib/subly/model.rb', line 56 def in_the_future? now = Time.now !!(starts_at > now && (ends_at.nil? || ends_at > now)) end |