mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
c81af6ae72
We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
28 lines
886 B
Ruby
28 lines
886 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Club < ActiveRecord::Base
|
|
has_one :membership, touch: true
|
|
has_many :memberships, inverse_of: false
|
|
has_many :members, through: :memberships
|
|
has_one :sponsor
|
|
has_one :sponsored_member, through: :sponsor, source: :sponsorable, source_type: "Member"
|
|
belongs_to :category
|
|
|
|
has_many :favourites, -> { where(memberships: { favourite: true }) }, through: :memberships, source: :member
|
|
|
|
scope :general, -> { left_joins(:category).where(categories: { name: "General" }).unscope(:limit) }
|
|
|
|
accepts_nested_attributes_for :membership
|
|
|
|
private
|
|
def private_method
|
|
"I'm sorry sir, this is a *private* club, not a *pirate* club"
|
|
end
|
|
end
|
|
|
|
class SuperClub < ActiveRecord::Base
|
|
self.table_name = "clubs"
|
|
|
|
has_many :memberships, class_name: "SuperMembership", foreign_key: "club_id"
|
|
has_many :members, through: :memberships
|
|
end
|