Sha256: 471a8ae1a760188591951406e03d0827874faae0abca395a8a013406405c7e3a

Contents?: true

Size: 1.65 KB

Versions: 30

Compression:

Stored size: 1.65 KB

Contents

module Merb::Generators
  
  class ModelGenerator < NamespacedGenerator

    
    def self.source_root
      File.join(super, 'component', 'model')
    end
    
    desc <<-DESC
      Generates a new model. You can specify an ORM different from what the rest
      of the application uses.
    DESC
    
    option :testing_framework, :desc => 'Testing framework to use (one of: rspec, test_unit)'
    option :orm, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
    
    first_argument :name, :required => true, :desc => "model name"
    second_argument :attributes, :as => :hash, :default => {}, :desc => "space separated model properties in form of name:type. Example: state:string"
    
    template :model_none, :orm => :none do |template|
      template.source = "app/models/%file_name%.rb"
      template.destination = "app/models" / base_path / "#{file_name}.rb"
    end
    
    template :spec, :testing_framework => :rspec do |template|
      template.source = 'spec/models/%file_name%_spec.rb'
      template.destination = "spec/models" / base_path / "#{file_name}_spec.rb"
    end
    
    template :test_unit, :testing_framework => :test_unit do |template|
      template.source = 'test/models/%file_name%_test.rb'
      template.destination = "test/models" / base_path / "#{file_name}_test.rb"
    end
    
    def attributes?
      self.attributes && !self.attributes.empty?
    end
    
    def attributes_for_accessor
      self.attributes.keys.map{|a| ":#{a}" }.compact.uniq.join(", ")
    end

    def after_generation
      STDOUT.puts "\n\nDon't forget to add model tests first."
    end
  end
  
  add :model, ModelGenerator
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
merb-gen-1.1.3 lib/generators/model.rb
merb-gen-1.1.2 lib/generators/model.rb
merb-gen-1.1.1 lib/generators/model.rb
merb-gen-1.1.0 lib/generators/model.rb
merb-gen-1.1.0.rc1 lib/generators/model.rb
merb-gen-1.1.0.pre lib/generators/model.rb
merb-gen-1.0.15 lib/generators/model.rb
merb-gen-1.0.14 lib/generators/model.rb
merb-gen-1.0.13 lib/generators/model.rb
merb-gen-1.0.12 lib/generators/model.rb
merb-gen-0.9.11 lib/generators/model.rb
merb-gen-0.9.13 lib/generators/model.rb
merb-gen-0.9.10 lib/generators/model.rb
merb-gen-0.9.12 lib/generators/model.rb
merb-gen-1.0.10 lib/generators/model.rb
merb-gen-1.0.1 lib/generators/model.rb
merb-gen-1.0.2 lib/generators/model.rb
merb-gen-0.9.9 lib/generators/model.rb
merb-gen-1.0.11 lib/generators/model.rb
merb-gen-1.0.3 lib/generators/model.rb