Sha256: eb13b2de164f924706538f7e5d0adf9662082187f582684e5f874c804e848337

Contents?: true

Size: 1.06 KB

Versions: 4

Compression:

Stored size: 1.06 KB

Contents

class <%= class_name %>
<% max = 2
  presets = {'Text' => ':lazy => false', 'String' => ':length => 500'}
  reserved_dm_names = DataMapper::Resource.instance_methods +
      DataMapper::Resource.private_instance_methods 
  Array(attributes).each do |attribute|
    if reserved_dm_names.include? attribute.name
      raise "reserved property name '#{attribute.name}'"
    elsif !DdModelGenerator::VALID_TYPES.include? attribute.type.to_s.camelcase
      raise "unknown property type '#{attribute.type}'"
    end
    max = attribute.name.size if attribute.name.size > max
  end -%>
  include DataMapper::Resource
  
  property :id,<%= " " * (max - 2) %> Serial
<% Array(attributes).each do |attribute|
     klass = attribute.type.to_s.camelcase
     more = presets.has_key?(klass) ? ", #{presets[klass]}" : ''
     pad = max - attribute.name.size
     rad = 13 - klass.size
     %>  property :<%= attribute.name %>, <%= " " * pad
     %><%= "#{klass}" %>, <%= " " * rad %>:required => true<%= more %>
<% end -%>
<% unless options[:skip_timestamps] -%>
  timestamps :at 
<% end -%>
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails_dm_datastore-0.2.11.pre generators/dd_model/templates/model.rb
rails_dm_datastore-0.2.9 generators/dd_model/templates/model.rb
rails_dm_datastore-0.2.8 generators/dd_model/templates/model.rb
rails_dm_datastore-0.2.6 generators/dd_model/templates/model.rb