Class: ExtensionModelGenerator

Inherits:
ModelGenerator
  • Object
show all
Defined in:
lib/generators/extension_model/extension_model_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runtime_args, runtime_options = {}) ⇒ ExtensionModelGenerator

Returns a new instance of ExtensionModelGenerator.



30
31
32
33
34
# File 'lib/generators/extension_model/extension_model_generator.rb', line 30

def initialize(runtime_args, runtime_options = {})
  runtime_args = runtime_args.dup
  @extension_name = runtime_args.shift
  super(runtime_args, runtime_options)
end

Instance Attribute Details

#extension_nameObject

Returns the value of attribute extension_name.



28
29
30
# File 'lib/generators/extension_model/extension_model_generator.rb', line 28

def extension_name
  @extension_name
end

Instance Method Details



67
68
69
# File 'lib/generators/extension_model/extension_model_generator.rb', line 67

def banner
  "Usage: #{$0} extension_model ExtensionName ModelName [field:type, field:type]"
end

#destination_rootObject



75
76
77
# File 'lib/generators/extension_model/extension_model_generator.rb', line 75

def destination_root
  File.join(RAILS_ROOT, extension_path)
end

#extension_pathObject



71
72
73
# File 'lib/generators/extension_model/extension_model_generator.rb', line 71

def extension_path
  File.join('vendor', 'extensions', @extension_name.underscore)
end

#extension_uses_rspec?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/generators/extension_model/extension_model_generator.rb', line 79

def extension_uses_rspec?
  File.exists?(File.join(destination_root, 'spec'))
end

#manifestObject



36
37
38
39
40
41
42
# File 'lib/generators/extension_model/extension_model_generator.rb', line 36

def manifest
  if extension_uses_rspec?
    rspec_manifest
  else
    super
  end
end

#rspec_manifestObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/generators/extension_model/extension_model_generator.rb', line 44

def rspec_manifest
  record do |m|
    # Check for class naming collisions.
    m.class_collisions class_path, class_name

    # Model, spec, and fixture directories.
    m.directory File.join('app/models', class_path)
    m.directory File.join('spec/models', class_path)
    # m.directory File.join('spec/fixtures', class_path)

    # Model class, spec and fixtures.
    m.template 'model:model.rb',      File.join('app/models', class_path, "#{file_name}.rb")
    # m.template 'model:fixtures.yml',  File.join('spec/fixtures', class_path, "#{table_name}.yml")
    m.template 'model_spec.rb',       File.join('spec/models', class_path, "#{file_name}_spec.rb")

    unless options[:skip_migration]
      m.migration_template 'model:migration.rb', 'db/migrate', :assigns => {
        :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
      }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
    end
  end
end