Sha256: 2ae0b72e7659850869479200f1c2ad91d9e92c9051c1c3c75722ea557264d42a

Contents?: true

Size: 1.69 KB

Versions: 18

Compression:

Stored size: 1.69 KB

Contents

require 'thor/group'

module DaemonKit
  module Generators
    class Error < Thor::Error
    end

    class Base < Thor::Group
      include Thor::Actions

      add_runtime_options!

      # Tries to get the description from a USAGE file one folder above the source
      # root otherwise uses a default description.
      def self.desc(description=nil)
        return super if description
        usage = File.expand_path(File.join(source_root, "..", "USAGE"))

        @desc ||= if File.exist?(usage)
          File.read(usage)
        else
          "Description:\n    Create #{base_name.humanize.downcase} files for #{generator_name} generator."
        end
      end

      protected

      def app_name
        @app_name = File.basename( destination_root )
      end

      # Small macro to add ruby as an option to the generator with proper
      # default value plus an instance helper method called shebang.
      #
      def self.add_shebang_option!
        class_option :ruby, :type => :string, :aliases => "-r", :default => Thor::Util.ruby_command,
                            :desc => "Path to the Ruby binary of your choice", :banner => "PATH"

        no_tasks {
          define_method :shebang do
            @shebang ||= begin
              command = if options[:ruby] == Thor::Util.ruby_command
                "/usr/bin/env #{File.basename(Thor::Util.ruby_command)}"
              else
                options[:ruby]
              end
              "#!#{command}"
            end
          end
        }
      end

      def self.namespace(name = nil)
        return super if name
        @namespace ||= super.sub(/_generator$/, '').sub(/:generators:/, ':').sub(/^daemon_kit:/, '')
      end

    end
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
daemon-kit-0.3.3 lib/daemon_kit/generators/base.rb
daemon-kit-0.3.2 lib/daemon_kit/generators/base.rb
daemon-kit-0.3.1 lib/daemon_kit/generators/base.rb
daemon-kit-0.3.0 lib/daemon_kit/generators/base.rb
daemon-kit-0.3.0.rc2 lib/daemon_kit/generators/base.rb
daemon-kit-0.3.0.rc1 lib/daemon_kit/generators/base.rb
daemon-kit-0.2.3 lib/daemon_kit/generators/base.rb
daemon-kit-0.2.1 lib/daemon_kit/generators/base.rb
daemon-kit-0.2.0 lib/daemon_kit/generators/base.rb
daemon-kit-0.1.8.2 lib/daemon_kit/generators/base.rb
amqp-daemon-kit-1.0.1 lib/daemon_kit/generators/base.rb
amqp-daemon-kit-0.1.8.2 lib/daemon_kit/generators/base.rb
amqp-daemon-kit-0.1.8.1 lib/daemon_kit/generators/base.rb
daemon-kit-0.1.8.1 lib/daemon_kit/generators/base.rb
daemon-kit-0.1.8 lib/daemon_kit/generators/base.rb
daemon-kit-0.1.8rc3 lib/daemon_kit/generators/base.rb
textgoeshere-daemon-kit-0.1.8.31 lib/daemon_kit/generators/base.rb
textgoeshere-daemon-kit-0.1.8rc3 lib/daemon_kit/generators/base.rb