Class: Locomotive::Membership

Inherits:
Object
  • Object
show all
Includes:
Locomotive::Mongoid::Document
Defined in:
app/models/locomotive/membership.rb

Instance Method Summary collapse

Instance Method Details

#_roleObject

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

#abilityObject



50
51
52
# File 'app/models/locomotive/membership.rb', line 50

def ability
  @ability ||= Locomotive::Ability.new(self., self.site)
end

#accountObject

validations ##



10
# File 'app/models/locomotive/membership.rb', line 10

belongs_to  :account, class_name: 'Locomotive::Account', validate: false

#emailObject



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. = 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..blank?
    :create_account
  elsif self.site.memberships.any? { |m| m. == self. && m._id != self._id }
    self.errors.add(:base, 'Already created')
    :already_created
  else
    self.save
    :save_it
  end
end

#roleObject

fields ##



7
# File 'app/models/locomotive/membership.rb', line 7

field :role, default: 'author'