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)


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

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

Instance Method Details

#api_tokenObject

aliases ##


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

alias_attribute :api_token, :api_key

#created_sitesObject

associations ##


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

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

#devise_mailerObject


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

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.


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

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 ##


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

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 ##


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

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