Module: Rea::MetaType::Entity::ClassMethods

Defined in:
lib/rea/meta_type/entity.rb

Instance Method Summary collapse

Instance Method Details

#grouping(*names) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/rea/meta_type/entity.rb', line 38

def grouping *names
  $options = names.extract_options!
  names.each do |name|
    attr_accessible "#{name}_id"
    belongs_to name, $options
  end
end

#groupsObject



36
# File 'lib/rea/meta_type/entity.rb', line 36

def groups; @@groups ||= [] ; end

#groups_for(name) ⇒ Object



46
47
48
49
# File 'lib/rea/meta_type/entity.rb', line 46

def groups_for name
  klass = Rea.context.symbol_table[name]
  klass.all
end

#item(name, options = {}, &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/rea/meta_type/entity.rb', line 55

def item name, options={}, &block
  if self.entity_type == :simple
    cattr_reader name
    $item = self.new
    options.keys.each do |key|
      $item.instance_variable_set("@#{key}", options[key])
    end if options
    self.class_variable_set "@@#{name}", $item
    items[$item.id] = $item
  else
    raise "not support #{self.entity_type} yet!" 
  end
end

#itemsObject



51
52
53
# File 'lib/rea/meta_type/entity.rb', line 51

def items
  @@items ||= {}
end

#setup(options = nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rea/meta_type/entity.rb', line 21

def setup options=nil
  options = {:entity_type=>:active_record}.merge(options)
  class_option_set :entity_type, options

  case
  when self.entity_type == :simple
    attr_accessor :id
    self.class_eval do
      def self.find id
        self.items[id]
      end
    end
  end
end

#specification(name, options = {}) ⇒ Object



70
71
72
# File 'lib/rea/meta_type/entity.rb', line 70

def specification name, options={}
  belongs_to name, options
end