Sha256: 15d5d59d6b64f42e151983a1b9b4497133aa9a3070f28f3186341134e7e77626

Contents?: true

Size: 1.67 KB

Versions: 10

Compression:

Stored size: 1.67 KB

Contents

class RakeCommander
  module Patcher
    module Application
      module RunMethod
        include RakeCommander::Patcher::Base

        class << self
          def target
            Rake::Application
          end

          def patch_prepend(_invoked_by)
            return unless target_defined?
            Rake::Application.prepend Patch
          end

          def target_defined?
            return true if defined?(target)
            puts "Warning (#{self}): undefined target #{target}"
            false
          end
        end

        module Patch
          include RakeCommander::Patcher::Debug

          # To extend the command line syntax we need to patch `Rake`, provided that
          # this gem's extended options are not in `argv` when `Rake` processes it.
          # @note we define an instance variable so we can know if the patch was applied when it started.
          # @note This patch only works fine if `Rake::Application#run` is **invoked after****
          #   **`RakeCommander` has been required**.
          #   * So by itself alone it allows to use `raked` executable that this gem provides.
          def run(argv = ARGV)
            @rake_commander_run_argv_patch = true unless instance_variable_defined?(:@rake_commander_run_argv_patch)
            RakeCommander.self_load
            rake_comm_debug "R U N  !", "\n", num: 1, pid: true
            rake_comm_debug "  ---> Command: #{$PROGRAM_NAME}"
            rake_comm_debug "  ---> ARGV: [#{argv.map {|a| "'#{a}'"}.join(', ')}]"
            argv = RakeCommander.argv_rake_native_arguments(argv)
            super(argv)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rake-commander-0.2.12 lib/rake-commander/patcher/application/run_method.rb
rake-commander-0.2.11 lib/rake-commander/patcher/application/run_method.rb
rake-commander-0.2.10 lib/rake-commander/patcher/application/run_method.rb
rake-commander-0.2.7 lib/rake-commander/patcher/application/run_method.rb
rake-commander-0.2.6 lib/rake-commander/patcher/application/run_method.rb
rake-commander-0.2.5 lib/rake-commander/patcher/application/run_method.rb
rake-commander-0.2.4 lib/rake-commander/patcher/application/run_method.rb
rake-commander-0.2.3 lib/rake-commander/patcher/application/run_method.rb
rake-commander-0.2.2 lib/rake-commander/patcher/application/run_method.rb
rake-commander-0.2.0 lib/rake-commander/patcher/application/run_method.rb