Module: ActiveRecordComposition

Defined in:
lib/active_record_composition.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.create_class(class_name, superclass, &block) ⇒ Object



34
35
36
37
# File 'lib/active_record_composition.rb', line 34

def self.create_class(class_name, superclass, &block)
  klass = Class.new superclass, &block
  Object.const_set class_name, klass
end

.included(base) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/active_record_composition.rb', line 39

def self.included(base)
  base.extend(ClassMethods)
  base.active_composite = self.create_class("#{base.name}ActiveComposite", ActiveRecord::Base) do
 
    def is_a?(compared)
      return true if self.class.name.gsub('ActiveComposite','') == compared.name
      return true if compared.name == 'ActiveRecord::Base'
      return true if self.class.name == compared.name
      return false
    end

  end
  base.active_composite.table_name = "#{base.name}s".underscore
end