Module: Ixtlan::Models::Domain

Defined in:
lib/ixtlan/models/domain.rb

Constant Summary collapse

ALL =
"ALL"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ixtlan/models/domain.rb', line 10

def self.included(model)
    model.send(:include, DataMapper::Resource)

    model.property :id, ::DataMapper::Types::Serial

    model.property :name, String, :required => true , :format => /^[a-z]+$|^#{ALL}$/, :length => 32, :unique_index => true

    model.timestamps :created_at

    model.modified_by Models::USER, :created_by

    model.class_eval <<-EOS, __FILE__, __LINE__
  def self.every
    first(:name => ALL)
  end

  def self.first_or_get!(id_or_name)
    first(:name => id_or_name) || get!(id_or_name)
  end

  def self.first_or_get(id_or_name)
    first(:name => id_or_name) || get(id_or_name)
  end
EOS
end

Instance Method Details

#==(other) ⇒ Object



40
41
42
# File 'lib/ixtlan/models/domain.rb', line 40

def ==(other)
  attribute_get(:name).eql?(other.attribute_get(:name))
end

#eql?Object



39
# File 'lib/ixtlan/models/domain.rb', line 39

alias :eql? :==

#hashObject



35
36
37
# File 'lib/ixtlan/models/domain.rb', line 35

def hash
  attribute_get(:name).hash
end