Sha256: 5f811e6fb17864118de8f17ef5e9fa9e4b1cfb80185a12b3ee3f6df1c23fe2bd

Contents?: true

Size: 1.13 KB

Versions: 14

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'eac_cli/runner/context_responders/base'

module EacCli
  module Runner
    module ContextResponders
      class Set < ::EacCli::Runner::ContextResponders::Base
        attr_reader :responders_names

        def initialize(context, method_name, responders_names)
          super(context, method_name)
          @responders_names = responders_names
        end

        def callable?
          responders_instances.any?(&:callable?)
        end

        def call(...)
          caller = responder_to_call
          return caller.call(...) if caller

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

        private

        def responder_class(class_name)
          ::EacCli::Runner::ContextResponders.const_get(class_name.to_s.camelize)
        end

        def responders_instances
          responders_names.lazy.map { |name| responder_class(name).new(context, method_name) }
        end

        def responder_to_call
          responders_instances.lazy.select(&:callable?).first
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
eac_cli-0.42.0 lib/eac_cli/runner/context_responders/set.rb
eac_cli-0.40.1 lib/eac_cli/runner/context_responders/set.rb
eac_cli-0.40.0 lib/eac_cli/runner/context_responders/set.rb
eac_cli-0.39.0 lib/eac_cli/runner/context_responders/set.rb
eac_cli-0.38.1 lib/eac_cli/runner/context_responders/set.rb
eac_tools-0.82.0 sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb
eac_tools-0.81.0 sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb
eac_tools-0.80.0 sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb
eac_tools-0.79.0 sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb
eac_tools-0.78.0 sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb
eac_tools-0.77.1 sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb
eac_tools-0.77.0 sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb
eac_cli-0.38.0 lib/eac_cli/runner/context_responders/set.rb
eac_tools-0.76.1 sub/eac_cli/lib/eac_cli/runner/context_responders/set.rb