class CustomMongo::Generators::ModelGenerator

Extend this class to add the “default” field.

Public Class Methods

new(args, *options) click to toggle source
Calls superclass method
# File lib/generators/custom_mongo/model_generator.rb, line 18
def initialize(args, *options)
  custom_attributes = args[1]
  args = [args[0]] # "super" expects the name as arg[0], then we custom parse the attributes
  super
  self.attributes = custom_attributes.map do |attribute|
    att = Rails::Generators::GeneratedAttribute.new(attribute[:name], attribute[:type].to_sym)
    att.default = attribute[:default]
    att
  end
end

Public Instance Methods

create_model_file() click to toggle source
# File lib/generators/custom_mongo/model_generator.rb, line 29
def create_model_file
  template File.join(File.dirname(__FILE__), 'model.rb.tt'), File.join('app/models', class_path, "#{file_name}.rb")
end