Sha256: 348678120c675d27438b909729d75aab567919528a7590ca62e5efa068e603d5

Contents?: true

Size: 1.26 KB

Versions: 24

Compression:

Stored size: 1.26 KB

Contents

module Riveter
  module Generators
    class CommandControllerGenerator < ::Rails::Generators::NamedBase
      source_root File.expand_path('../templates', __FILE__)

      check_class_collision :suffix => 'CommandController'

      argument :new_action,
               :type => :string,
               :default => 'new',
               :banner => 'new_action'

      argument :create_action,
               :type => :string,
               :default => 'create',
               :banner => 'create_action'

      def create_command_controller_file
        template 'command_controller.rb', File.join('app/controllers', class_path, "#{file_name}_command_controller.rb")
      end

      def create_module_file
        return if regular_class_path.empty?
        template 'module.rb', File.join('app/controllers', "#{class_path.join('/')}.rb") if behavior == :invoke
      end

      def add_command_route
        route "command :#{class_name.underscore}#{additional_args}"
      end

      hook_for :template_engine
      hook_for :test_framework, :as => :command_controller

      def additional_args
        ((new_action == 'new') ? '' : ", :new_action => :#{new_action}") +
        ((create_action == 'create') ? '' : ", :create_action => :#{create_action}")
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
riveter-0.8.3 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.8.2 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.8.1 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.8.0 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.7.0 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.6.0 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.3.0 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.2.1 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.2.0 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.1.1 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.0.15 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.0.14 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.0.13 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.0.12 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.0.11 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.0.10 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.0.9 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.0.8 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.0.7 lib/generators/riveter/command_controller/command_controller_generator.rb
riveter-0.0.6 lib/generators/riveter/command_controller/command_controller_generator.rb