Class: Congo::ContentType

Inherits:
Object
  • Object
show all
Includes:
Migration, Validation, MongoMapper::Document
Defined in:
lib/congo/content_type.rb

Instance Method Summary collapse

Methods included from Migration

included

Methods included from Validation

included

Instance Method Details

#embeddedObject

keys



8
# File 'lib/congo/content_type.rb', line 8

key :embedded, Boolean, :default => false

#scopeObject

associations



17
# File 'lib/congo/content_type.rb', line 17

belongs_to :scope, :polymorphic => true

#to_constObject

methods



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
# File 'lib/congo/content_type.rb', line 30

def to_const
  klass = Class.new
  if self.embedded?
    klass.send(:include, MongoMapper::EmbeddedDocument)
  else
    klass.send(:include, MongoMapper::Document)
    klass.timestamps!
    set_collection_name(klass)
    apply_scope(klass)
  end
  
  klass.class_eval <<-EOV
    def content_type
      @content_type ||= self.class.content_type
    end
    
    def self.content_type
      Congo::ContentType.find('#{self._id}')
    end
  EOV
  
  (klass)
  apply_migration(klass)
  klass
end