Class: ExtensionModelGenerator
- Inherits:
-
ModelGenerator
- Object
- ModelGenerator
- ExtensionModelGenerator
- Defined in:
- lib/generators/extension_model/extension_model_extension.rb,
lib/generators-rails2/extension_model/extension_model_generator.rb
Instance Attribute Summary collapse
-
#extension_name ⇒ Object
Returns the value of attribute extension_name.
Instance Method Summary collapse
- #add_options!(opt) ⇒ Object
- #banner ⇒ Object
- #destination_root ⇒ Object
- #directories ⇒ Object
- #extension_path ⇒ Object
- #extension_uses_rspec? ⇒ Boolean
- #files ⇒ Object
-
#initialize(runtime_args, runtime_options = {}) ⇒ ExtensionModelGenerator
constructor
A new instance of ExtensionModelGenerator.
- #manifest ⇒ Object
- #parts ⇒ Object
- #rspec_manifest ⇒ Object
Constructor Details
#initialize(runtime_args, runtime_options = {}) ⇒ ExtensionModelGenerator
Returns a new instance of ExtensionModelGenerator.
9 10 11 12 13 |
# File 'lib/generators-rails2/extension_model/extension_model_generator.rb', line 9 def initialize(runtime_args, = {}) runtime_args = runtime_args.dup @extension_name = runtime_args.shift super(runtime_args, ) end |
Instance Attribute Details
#extension_name ⇒ Object
Returns the value of attribute extension_name.
6 7 8 |
# File 'lib/generators-rails2/extension_model/extension_model_generator.rb', line 6 def extension_name @extension_name end |
Instance Method Details
#add_options!(opt) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/generators-rails2/extension_model/extension_model_generator.rb', line 62 def (opt) opt.separator '' opt.separator 'Options:' opt.on("--with-test-unit", "Use Test::Unit tests instead sof RSpec.") { |v| [:with_test_unit] = v } end |
#banner ⇒ Object
46 47 48 |
# File 'lib/generators-rails2/extension_model/extension_model_generator.rb', line 46 def "Usage: #{$0} extension_model ExtensionName ModelName [field:type, field:type]" end |
#destination_root ⇒ Object
54 55 56 |
# File 'lib/generators-rails2/extension_model/extension_model_generator.rb', line 54 def destination_root File.join(RAILS_ROOT, extension_path) end |
#directories ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/generators/extension_model/extension_model_extension.rb', line 9 def directories empty_directory File.join(class_path, 'app/models') unless test_unit? empty_directory File.join(class_path, 'spec/models') end end |
#extension_path ⇒ Object
50 51 52 |
# File 'lib/generators-rails2/extension_model/extension_model_generator.rb', line 50 def extension_path File.join('vendor', 'extensions', @extension_name.underscore) end |
#extension_uses_rspec? ⇒ Boolean
65 66 67 |
# File 'lib/generators/extension_model/extension_model_extension.rb', line 65 def extension_uses_rspec? File.exists?(File.join(destination_root, 'spec')) && ![:with_test_unit] end |
#files ⇒ Object
17 18 19 20 |
# File 'lib/generators/extension_model/extension_model_extension.rb', line 17 def files template 'models.rb', File.join(class_path, 'spec/controllers', "#{file_name}_controller_spec.rb") end |
#manifest ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/generators-rails2/extension_model/extension_model_generator.rb', line 15 def manifest if extension_uses_rspec? rspec_manifest else super end end |
#parts ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/generators/extension_model/extension_model_extension.rb', line 37 def parts # Spec and view template for each action. actions.each do |a| @action = a template 'view_spec.rb', File.join(class_path, 'spec/views', file_name, "#{@action}_view_spec.rb") template 'view.html.haml', File.join(class_path, 'app/views', file_name, "#{@action}.html.haml") end end |
#rspec_manifest ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators-rails2/extension_model/extension_model_generator.rb', line 23 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 [: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 |