Sha256: 80c44fbe17b254860f2375a39b116906b0629f66423b9607b1f05fcde8557d60

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

class HoboModelGenerator < Rails::Generator::NamedBase

  def manifest
    record do |m|
      # Check for class naming collisions.
      m.class_collisions class_path, class_name, "#{class_name}Test"

      # Model, test, and fixture directories.
      m.directory File.join('app/models', class_path)
      m.directory File.join('test/unit', class_path)
      m.directory File.join('test/fixtures', class_path)
      m.directory File.join("app/viewhints")

      # Model class, unit test, and fixtures.
      m.template 'model.rb',      File.join('app/models',    class_path, "#{file_name}.rb")
      m.template 'hints.rb',      File.join('app/viewhints', class_path, "#{file_name}_hints.rb")
      m.template 'unit_test.rb',  File.join('test/unit',     class_path, "#{file_name}_test.rb")
      m.template 'fixtures.yml',  File.join('test/fixtures', class_path, "#{table_name}.yml")
    end
  end

  protected
    def banner
      "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]"
    end
    
    def max_attribute_length
      attributes.*.name.*.length.max
    end
    
    def field_attributes
      attributes.reject { |a| a.name == "bt" || a.name == "hm" }
    end
    
    def hms
      attributes.select { |a| a.name == "hm" }.*.type
    end

    def bts
      attributes.select { |a| a.name == "bt" }.*.type
    end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hobo-1.1.0 rails_generators/hobo_model/hobo_model_generator.rb
hobo-1.1.0.pre4 rails_generators/hobo_model/hobo_model_generator.rb
hobo-1.1.0.pre3 rails_generators/hobo_model/hobo_model_generator.rb
hobo-1.1.0.pre2 rails_generators/hobo_model/hobo_model_generator.rb
hobo-1.1.0.pre0 rails_generators/hobo_model/hobo_model_generator.rb