2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2008-03-21 14:09:03 -04:00
|
|
|
class Membership < ActiveRecord::Base
|
2017-06-25 08:55:38 -04:00
|
|
|
enum type: %i(Membership CurrentMembership SuperMembership SelectedMembership TenantMembership)
|
2008-03-21 14:09:03 -04:00
|
|
|
belongs_to :member
|
|
|
|
belongs_to :club
|
|
|
|
end
|
|
|
|
|
|
|
|
class CurrentMembership < Membership
|
|
|
|
belongs_to :member
|
|
|
|
belongs_to :club
|
|
|
|
end
|
2011-05-11 03:55:36 -04:00
|
|
|
|
2013-09-23 21:13:08 -04:00
|
|
|
class SuperMembership < Membership
|
2016-08-06 12:26:20 -04:00
|
|
|
belongs_to :member, -> { order("members.id DESC") }
|
2013-09-23 21:13:08 -04:00
|
|
|
belongs_to :club
|
|
|
|
end
|
|
|
|
|
2011-05-11 03:55:36 -04:00
|
|
|
class SelectedMembership < Membership
|
|
|
|
def self.default_scope
|
|
|
|
select("'1' as foo")
|
|
|
|
end
|
|
|
|
end
|
2015-08-12 20:14:42 -04:00
|
|
|
|
|
|
|
class TenantMembership < Membership
|
|
|
|
cattr_accessor :current_member
|
|
|
|
|
|
|
|
belongs_to :member
|
|
|
|
belongs_to :club
|
|
|
|
|
|
|
|
default_scope -> {
|
|
|
|
if current_member
|
|
|
|
where(member: current_member)
|
|
|
|
else
|
|
|
|
all
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|