Sha256: b986070897272ab5892180913fce82c6babee5b5a8fef3d992cd59ad191fa773

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

# -*- encoding : utf-8 -*-
require 'rails/generators'
require 'mdwa/dsl'

module Mdwa
  module Generators
    class EntityGenerator < Rails::Generators::Base
      
      source_root File.expand_path("../templates", __FILE__)

      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
        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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mdd-3.1.4 lib/generators/mdwa/entity/entity_generator.rb
mdd-3.1.2 lib/generators/mdwa/entity/entity_generator.rb
mdd-3.1.1 lib/generators/mdwa/entity/entity_generator.rb