Module: Rea::MetaType::Entity::ClassMethods
- Defined in:
- lib/rea/meta_type/entity.rb
Instance Method Summary collapse
- #grouping(*names) ⇒ Object
- #groups ⇒ Object
- #groups_for(name) ⇒ Object
- #item(name, options = {}, &block) ⇒ Object
- #items ⇒ Object
- #setup(options = nil) ⇒ Object
- #specification(name, options = {}) ⇒ Object
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 = names. names.each do |name| attr_accessible "#{name}_id" belongs_to name, end end |
#groups ⇒ Object
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, ={}, &block if self.entity_type == :simple cattr_reader name $item = self.new .keys.each do |key| $item.instance_variable_set("@#{key}", [key]) end if self.class_variable_set "@@#{name}", $item items[$item.id] = $item else raise "not support #{self.entity_type} yet!" end end |
#items ⇒ Object
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 =nil = {:entity_type=>:active_record}.merge() class_option_set :entity_type, 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, ={} belongs_to name, end |