Sha256: 2c01b3f6112ca4ac5411b72165fb2ebe5deb18eefca8c0b772176b6fe1374716

Contents?: true

Size: 1.19 KB

Versions: 68

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'

module EacCli
  module Runner
    class Context
      attr_reader :argv, :parent, :program_name, :runner

      def initialize(runner, *context_args)
        options = context_args.extract_options!
        @argv = (context_args[0] || options.delete(:argv) || ARGV).dup.freeze
        @parent = context_args[1] || options.delete(:parent)
        @program_name = options.delete(:program_name)
        @runner = runner
      end

      # Call a method in the runner or in one of it ancestors.
      def call(method_name, *args)
        return runner.send(method_name, *args) if runner.respond_to?(method_name)
        return parent_call(method_name, *args) if parent.present?

        raise ::NameError, "No method \"#{method_name}\" found in #{runner} or in its ancestors"
      end

      protected

      def parent_call(method_name, *args)
        return parent.context(method_name, *args) if parent.respond_to?(:context)
        return parent.runner_context.call(method_name, *args) if parent.respond_to?(:runner_context)

        raise "Parent #{parent} do not respond to .context or .runner_context (Runner: #{runner})"
      end
    end
  end
end

Version data entries

68 entries across 68 versions & 3 rubygems

Version Path
avm-tools-0.103.0 vendor/eac_cli/lib/eac_cli/runner/context.rb
eac_cli-0.21.1 lib/eac_cli/runner/context.rb
ehbrs-tools-0.22.0 vendor/eac_cli/lib/eac_cli/runner/context.rb
eac_cli-0.21.0 lib/eac_cli/runner/context.rb
eac_cli-0.20.4 lib/eac_cli/runner/context.rb
eac_cli-0.20.3 lib/eac_cli/runner/context.rb
avm-tools-0.102.2 vendor/eac_cli/lib/eac_cli/runner/context.rb
eac_cli-0.20.2 lib/eac_cli/runner/context.rb
avm-tools-0.102.1 vendor/eac_cli/lib/eac_cli/runner/context.rb
eac_cli-0.20.1 lib/eac_cli/runner/context.rb
eac_cli-0.20.0 lib/eac_cli/runner/context.rb
avm-tools-0.102.0 vendor/eac_cli/lib/eac_cli/runner/context.rb
eac_cli-0.19.0 lib/eac_cli/runner/context.rb
avm-tools-0.101.0 vendor/eac_cli/lib/eac_cli/runner/context.rb
eac_cli-0.18.0 lib/eac_cli/runner/context.rb
avm-tools-0.100.0 vendor/eac_cli/lib/eac_cli/runner/context.rb
ehbrs-tools-0.21.0 vendor/eac_cli/lib/eac_cli/runner/context.rb
avm-tools-0.99.1 vendor/eac_cli/lib/eac_cli/runner/context.rb
eac_cli-0.17.0 lib/eac_cli/runner/context.rb
avm-tools-0.99.0 vendor/eac_cli/lib/eac_cli/runner/context.rb