Module: DataMapper::Is::Versioned::ClassMethods

Defined in:
lib/dm-is-versioned/is/versioned.rb

Instance Method Summary collapse

Instance Method Details

#const_missing(name) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/dm-is-versioned/is/versioned.rb', line 74

def const_missing(name)
  if name == :Version
    model = DataMapper::Model.new(name, self)

    properties.each do |property|
      type = case property
        when DataMapper::Property::Discriminator then Class
        when DataMapper::Property::Serial        then Integer
      else
        property.class
      end

      options = property.options.merge(:key => property.name == @on)

      options[:key] = true if options.delete(:serial)

      model.property(property.name, type, options)
    end

    model
  else
    super
  end
end