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