Sha256: 9c00a3b285873b02e0e3d1f8558ddd3d98ff1271487227cc189655458f8e5c5e

Contents?: true

Size: 1.72 KB

Versions: 1

Compression:

Stored size: 1.72 KB

Contents

module Tennpipes
  module Generators
    ##
    # Responsible for generating new task file for Tennpipes application.
    #
    class Task < Thor::Group
      include Thor::Actions
      include Tennpipes::Generators::Actions
      include Tennpipes::Generators::Components::Actions

      Tennpipes::Generators.add_generator(:task, self)

      class << self
        def source_root; File.expand_path(File.dirname(__FILE__)); end
        def banner; "tennpipes-init task [name]"; end
      end

      desc "Description:\n\n\ttennpipes-init task generates a new task file."

      argument     :name,        :desc => 'The name of your application task'
      class_option :root,        :desc => 'The root destination',                     :aliases => '-r', :default => '.', :type => :string
      class_option :description, :desc => 'The description of your application task', :aliases => '-d', :default => nil, :type => :string
      class_option :namespace,   :desc => 'The namespace of your application task',   :aliases => '-n', :default => nil, :type => :string

      # Show help if no ARGV given
      require_arguments!

      def create_task
        self.destination_root = options[:root]
        if in_app_root?
          app        = options[:app]
          @task_name = name.to_s.underscore
          @namespace = options[:namespace].underscore if options[:namespace]
          @desc      = options[:description]
          filename   = @task_name + ".rake"
          filename   = "#{@namespace}_#{filename}" if @namespace

          template 'templates/task.rb.tt', destination_root('tasks', filename)
        else
          say 'You are not at the root of a Tennpipes application! (config/boot.rb not found)'
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tennpipes-init-3.6.6 lib/tennpipes-init/generators/task.rb