Sha256: f73ad5cceea8bf60d3aa96ba0806eb5603c3215f26f0d3f53d698d10c67707b1

Contents?: true

Size: 954 Bytes

Versions: 26

Compression:

Stored size: 954 Bytes

Contents

module Mtwarden
	class Account < ActiveRecord::Base

		belongs_to :owner, :class_name => "Mtwarden::User"
		accepts_nested_attributes_for :owner

		belongs_to :plan, :class_name => "Mtwarden::Plan"

		validates :subdomain, :presence => true, :uniqueness => true
		validates :name, presence: true

		has_many :members, :class_name => "Mtwarden::Member"
		has_many :users, :through => :members

		EXCLUDED_SUBDOMAINS = %w(admin)
		validates_exclusion_of :subdomain, :in => EXCLUDED_SUBDOMAINS, 
		:message => "is not allowed. Please choose another subdomain."

		validates_format_of :subdomain, :with => /\A[\w\-]+\Z/i,
		:message => "is not allowed. Please choose another subdomain." 

		before_validation do
			self.subdomain = subdomain.to_s.downcase
		end

		def self.create_with_owner(params={})
			account = new(params)
			if account.save
				account.users << account.owner
			end
			account
		end

		def owner?(user)
			owner == user
		end
	end

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
mtwarden-4.1.2 app/models/mtwarden/account.rb
mtwarden-4.1.1 app/models/mtwarden/account.rb
mtwarden-4.1.0 app/models/mtwarden/account.rb
mtwarden-4.0.0 app/models/mtwarden/account.rb
mtwarden-3.6.2 app/models/mtwarden/account.rb
mtwarden-3.6.1 app/models/mtwarden/account.rb
mtwarden-3.6.0 app/models/mtwarden/account.rb
mtwarden-3.5.1 app/models/mtwarden/account.rb
mtwarden-3.5.0 app/models/mtwarden/account.rb
mtwarden-3.3.4 app/models/mtwarden/account.rb
mtwarden-3.3.3 app/models/mtwarden/account.rb
mtwarden-3.3.2 app/models/mtwarden/account.rb
mtwarden-3.3.1 app/models/mtwarden/account.rb
mtwarden-3.3.0 app/models/mtwarden/account.rb
mtwarden-3.2.0 app/models/mtwarden/account.rb
mtwarden-3.1.2 app/models/mtwarden/account.rb
mtwarden-3.1.1 app/models/mtwarden/account.rb
mtwarden-3.1.0 app/models/mtwarden/account.rb
mtwarden-3.0.3 app/models/mtwarden/account.rb
mtwarden-3.0.2 app/models/mtwarden/account.rb