Sha256: 5f763b92554c575e9ad29ba505d448ec979bce542d8571d6cbff332825e70bd7

Contents?: true

Size: 1.99 KB

Versions: 264

Compression:

Stored size: 1.99 KB

Contents

require "rake"
require "rake/dsl_definition"

class Thor
  # Adds a compatibility layer to your Thor classes which allows you to use
  # rake package tasks. For example, to use rspec rake tasks, one can do:
  #
  #   require 'thor/rake_compat'
  #   require 'rspec/core/rake_task'
  #
  #   class Default < Thor
  #     include Thor::RakeCompat
  #
  #     RSpec::Core::RakeTask.new(:spec) do |t|
  #       t.spec_opts = ['--options', './.rspec']
  #       t.spec_files = FileList['spec/**/*_spec.rb']
  #     end
  #   end
  #
  module RakeCompat
    include Rake::DSL if defined?(Rake::DSL)

    def self.rake_classes
      @rake_classes ||= []
    end

    def self.included(base)
      # Hack. Make rakefile point to invoker, so rdoc task is generated properly.
      rakefile = File.basename(caller[0].match(/(.*):\d+/)[1])
      Rake.application.instance_variable_set(:@rakefile, rakefile)
      rake_classes << base
    end
  end
end

# override task on (main), for compatibility with Rake 0.9
instance_eval do
  alias rake_namespace namespace

  def task(*)
    task = super

    if klass = Thor::RakeCompat.rake_classes.last # rubocop:disable AssignmentInCondition
      non_namespaced_name = task.name.split(":").last

      description = non_namespaced_name
      description << task.arg_names.map { |n| n.to_s.upcase }.join(" ")
      description.strip!

      klass.desc description, Rake.application.last_description || non_namespaced_name
      Rake.application.last_description = nil
      klass.send :define_method, non_namespaced_name do |*args|
        Rake::Task[task.name.to_sym].invoke(*args)
      end
    end

    task
  end

  def namespace(name)
    if klass = Thor::RakeCompat.rake_classes.last # rubocop:disable AssignmentInCondition
      const_name = Thor::Util.camel_case(name.to_s).to_sym
      klass.const_set(const_name, Class.new(Thor))
      new_klass = klass.const_get(const_name)
      Thor::RakeCompat.rake_classes << new_klass
    end

    super
    Thor::RakeCompat.rake_classes.pop
  end
end

Version data entries

264 entries across 258 versions & 38 rubygems

Version Path
honeybadger-4.5.3 vendor/cli/thor/rake_compat.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/thor-0.20.3/lib/thor/rake_compat.rb
tdiary-5.1.0 vendor/bundle/gems/thor-0.20.3/lib/thor/rake_compat.rb
spec_fill-0.1.2 vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/rake_compat.rb
spec_fill-0.1.1 vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/rake_compat.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/thor-0.20.3/lib/thor/rake_compat.rb
spec_fill-0.1.0 vendor/bundle/ruby/2.6.0/gems/thor-0.20.3/lib/thor/rake_compat.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/thor-0.20.3/lib/thor/rake_compat.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/thor-0.20.3/lib/thor/rake_compat.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/thor-0.20.3/lib/thor/rake_compat.rb
honeybadger-4.5.2 vendor/cli/thor/rake_compat.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/thor-0.20.3/lib/thor/rake_compat.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/thor-0.20.3/lib/thor/rake_compat.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/thor-0.20.3/lib/thor/rake_compat.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/thor-0.20.3/lib/thor/rake_compat.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/thor-0.20.3/lib/thor/rake_compat.rb
honeybadger-4.5.1 vendor/cli/thor/rake_compat.rb
spiral_form-0.1.1 vendor/bundle/gems/thor-0.20.3/lib/thor/rake_compat.rb
spiral_form-0.1.0 vendor/bundle/gems/thor-0.20.3/lib/thor/rake_compat.rb
honeybadger-4.5.0 vendor/cli/thor/rake_compat.rb