Class Domain
In: app/models/domain.rb
Parent: ActiveRecord::Base

Methods

Public Class methods

turns the argument (expected to be a String) into a domain name that is accepted, by removing any leading ‘www.’ and turning the downcasing it.

[Source]

    # File app/models/domain.rb, line 39
39:   def self.extract_domain_name(name)
40:     name.downcase.sub(/^www\./, '')
41:   end

finds a domain by its name. The argument name can start with "www.", but it will be removed before searching. So searching for ‘www.example.net’ is exactly the same as searching for just ‘example.net‘

[Source]

    # File app/models/domain.rb, line 33
33:   def self.find_by_name(name)
34:     self.find(:first, :conditions => [ 'name = ?', self.extract_domain_name(name) ])
35:   end

Public Instance methods

detects the Environment to which this domain belongs, either if it‘s directly owned by one, or through a profile who owns the domain but belongs to a Environment.

[Source]

    # File app/models/domain.rb, line 46
46:   def environment
47:     case owner
48:     when Environment
49:       owner
50:     when Profile
51:       owner.environment
52:     end
53:   end

returns the profile associated to this domain. Returns nil if the domain is not directly associated with a profile.

[Source]

    # File app/models/domain.rb, line 57
57:   def profile
58:     case owner
59:     when Environment
60:       nil
61:     when Profile
62:       owner
63:     end
64:   end

checks validations that could not be expressed using Rails’ predefined validations. In particular:

  • name must not start with ‘www.’

[Source]

    # File app/models/domain.rb, line 18
18:   def validate
19:     if self.name =~ /^www\./
20:       self.errors.add(:name, _('%{fn} must not start with www.'))
21:     end
22:   end

[Validate]