This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Subscription::Plan | |
has_many :scan_frequencies | |
def scan_frequencies_sorted | |
scan_frequencies.sort do |a, b| | |
a.frequency.times_per_year <=> b.frequency.times_per_year | |
end | |
end | |
end | |
class Subscription::ScanFrequency |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# A user is active during a period if it has any subscriptions | |
# that are active during that period | |
def active?(start_date, end_date) | |
subscriptions.active_in_period(start_date, end_date).any? | |
end | |
end | |
# Lookup User and see if they are active |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# A user is only active if it has any subscriptions that are still active | |
def active? | |
subscriptions.active.any? | |
end | |
end | |
class AdminUser < User | |
# Admin users do not have subscriptions and are always active | |
def active?(*) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AdminUser < User | |
# Admin users do not have subscriptions and are always active | |
def active?(*) | |
true | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.find(1).active?(start_date, end_date) | |
=> false | |
User.find(42).active?(start_date, end_date) | |
=> ArgumentError: wrong number of arguments (2 for 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# A user is active during a period if it has any subscriptions that | |
#are active during that period | |
def active?(start_date, end_date) | |
subscriptions.active_in_period(start_date, end_date).any? | |
end | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.find(1).active? | |
=> true | |
User.find(42).active? | |
=> true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
# A user is only active if it has any subscriptions that are still active | |
def active? | |
subscriptions.active.any? | |
end | |
end | |
class AdminUser < User | |
# Admin users do not have subscriptions and are always active | |
def active? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Always returns true, ignores arguments | |
def always_true(*) | |
true | |
end | |
always_true | |
=> true | |
always_true(false) | |
=> true |
NewerOlder