Class: Domain::HeadingBased::DomainMethods

Inherits:
Module
  • Object
show all
Defined in:
lib/alf-core/ext/domain/heading_based.rb

Instance Method Summary collapse

Constructor Details

#initialize(master_class, gt) ⇒ DomainMethods

Returns a new instance of DomainMethods.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/alf-core/ext/domain/heading_based.rb', line 25

def initialize(master_class, gt)
  define_method(:generating_type){
    gt
  }
  define_method(:<=>){|other|
    return nil unless other.ancestors.include?(master_class)
    return -1 if other == master_class
    to_heading <=> other.to_heading
  }
  define_method(:===){|value|
    super(value) || (value.is_a?(master_class) && self >= value.class)
  }
  define_method(:hash){
    @hash ||= 37*master_class.hash + generating_type.hash
  }
  define_method(:==){|other|
    other.is_a?(Class) &&
    other.superclass==master_class &&
    other.to_heading==to_heading
  }
  define_method(:coerce){|arg|
    master_class.coercions.apply(arg, self)
  }
  define_method(:to_heading){
    @heading ||= Alf::Heading.coerce(generating_type)
  }
  define_method(:to_ruby_literal){
    "#{master_class.name}[#{Alf::Support.to_ruby_literal(to_heading.to_hash)}]"
  }
  alias_method :name, :to_ruby_literal
  alias_method :to_s, :to_ruby_literal
  alias_method :inspect, :to_ruby_literal
end