lib/generators/mdwa/entity/entity_generator.rb in mdd-3.0.4 vs lib/generators/mdwa/entity/entity_generator.rb in mdd-3.0.6

- old
+ new

@@ -1,9 +1,7 @@ # -*- encoding : utf-8 -*- - require 'rails/generators' - require 'mdwa/dsl' module Mdwa module Generators class EntityGenerator < Rails::Generators::Base @@ -12,13 +10,21 @@ argument :name, :type => :string, :banner => 'Entity name' class_option :user, :type => :boolean, :default => false, :desc => 'Is this entity a loggable user?' class_option :no_comments, :type => :boolean, :default => false, :desc => 'Generates entity without comments.' + class_option :requirement, :type => :string, :desc => 'Requirement alias' def code_generation - template 'entity.rb', "#{MDWA::DSL::STRUCTURAL_PATH}#{MDWA::DSL::Entity.new(name).file_name}.rb" + file_name = "#{MDWA::DSL::STRUCTURAL_PATH}#{MDWA::DSL::Entity.new(name).file_name}.rb" + # if file doesn't exist, create it + # if file exists, include the in_requirements clause + if !File.exist?( Rails.root + file_name ) + template 'entity.rb', file_name + else + append_to_file( file_name, "\nMDWA::DSL.entity('#{name.singularize.camelize}').in_requirements << '#{options.requirement}'" ) unless options.requirement.blank? + end end end # entity end #generators -end #mdwa +end #mdwa \ No newline at end of file