Class: Locomotive::Membership
- Inherits:
-
Object
- Object
- Locomotive::Membership
- Includes:
- Locomotive::Mongoid::Document
- Defined in:
- app/models/locomotive/membership.rb
Instance Method Summary collapse
-
#_role ⇒ Object
methods ##.
- #ability ⇒ Object
-
#account ⇒ Object
validations ##.
- #email ⇒ Object
- #email=(email) ⇒ Object
- #process! ⇒ Object
-
#role ⇒ Object
fields ##.
Instance Method Details
#_role ⇒ Object
methods ##
22 23 24 25 26 |
# File 'app/models/locomotive/membership.rb', line 22 Locomotive::Ability::ROLES.each do |_role| define_method("#{_role}?") do self.role == _role end end |
#ability ⇒ Object
50 51 52 |
# File 'app/models/locomotive/membership.rb', line 50 def ability @ability ||= Locomotive::Ability.new(self.account, self.site) end |
#account ⇒ Object
validations ##
10 |
# File 'app/models/locomotive/membership.rb', line 10 belongs_to :account, class_name: 'Locomotive::Account', validate: false |
#email ⇒ Object
28 |
# File 'app/models/locomotive/membership.rb', line 28 def email; @email; end |
#email=(email) ⇒ Object
30 31 32 33 |
# File 'app/models/locomotive/membership.rb', line 30 def email=(email) @email = email self.account = Locomotive::Account.where(email: email).first end |
#process! ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/locomotive/membership.rb', line 35 def process! if @email.blank? self.errors.add_on_blank(:email) :error elsif self.account.blank? :create_account elsif self.site.memberships.any? { |m| m.account_id == self.account_id && m._id != self._id } self.errors.add(:base, 'Already created') :already_created else self.save :save_it end end |
#role ⇒ Object
fields ##
7 |
# File 'app/models/locomotive/membership.rb', line 7 field :role, default: 'author' |