Class: Locomotive::Account

Inherits:
Object
  • Object
show all
Includes:
Concerns::Account::ApiKey, Mongoid::Document
Defined in:
app/models/locomotive/account.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Account::ApiKey

#regenerate_api_key, #regenerate_api_key!

Class Method Details

.find_by_email(email) ⇒ Object

Find the first account matching the email parameter

Parameters:

  • email (String)

    The email

Returns:

  • (Object)

    The account or nil (if none)



72
73
74
# File 'app/models/locomotive/account.rb', line 72

def self.find_by_email(email)
  where(email: email).first
end

Instance Method Details

#api_tokenObject

aliases ##



49
# File 'app/models/locomotive/account.rb', line 49

alias_attribute :api_token, :api_key

#created_sitesObject

associations ##



36
# File 'app/models/locomotive/account.rb', line 36

has_many :created_sites, class_name: 'Locomotive::Site', validate: false, autosave: false

#devise_mailerObject



76
77
78
# File 'app/models/locomotive/account.rb', line 76

def devise_mailer
  Locomotive::DeviseMailer
end

#local_admin?Boolean

Tell if the account has admin privileges for one (at least) of his/her sites.

Returns:

  • (Boolean)

    True if admin in one of his/her sites.



62
63
64
# File 'app/models/locomotive/account.rb', line 62

def local_admin?
  Site.where(memberships: { '$elemMatch' => { account_id: self._id, role: :admin } }).count > 0
end

#nameObject

validations ##



26
# File 'app/models/locomotive/account.rb', line 26

field :name

#orderedObject

scopes ##



42
# File 'app/models/locomotive/account.rb', line 42

scope :ordered,   -> { order_by(name: :asc) }

#remember_created_atObject

devise fields (need to be declared since 2.x) ##



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

field :remember_created_at,     type: Time

#sitesObject

methods ##



53
54
55
# File 'app/models/locomotive/account.rb', line 53

def sites
  @sites ||= Site.where('memberships.account_id' => self._id)
end