Sha256: f9ca9a4ab068ef775789f95c5ef1d620e490de9976ad807648d7ef69c4197afa

Contents?: true

Size: 1.48 KB

Versions: 17

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require 'eac_config/node'
require 'eac_fs/contexts'
require 'eac_ruby_utils/core_ext'
require 'eac_ruby_utils/speaker'

module EacRubyBase0
  module Runner
    module Contexts
      def on_context(&block)
        top_block = block
        available_contexts.each do |context|
          next if context.object.any?

          last_block = top_block
          top_block = ::Proc.new { context.object.on(context.builder.call, &last_block) }
        end
        top_block.call
      end

      private

      # @return [Array<EacRubyUtils::Struct>]
      def available_contexts
        (filesystem_available_contexts + [
          [:config, ::EacConfig::Node.context,
           -> { runner_context.call(:application).build_config }],
          [:speaker, ::EacRubyUtils::Speaker.context, -> { build_speaker }]
        ]).map { |row| available_context_row_to_struct(row) }
      end

      def available_context_row_to_struct(row)
        %i[type object builder].zip(row).to_h.to_struct
      end

      def build_speaker
        options = {}
        options[:err_out] = ::StringIO.new if parsed.quiet?
        options[:in_in] = ::EacCli::Speaker::InputBlocked.new if parsed.no_input?
        ::EacCli::Speaker.new(options)
      end

      def filesystem_available_contexts
        ::EacFs::Contexts::TYPES.map do |type|
          key = "fs_#{type}".to_sym
          [key, ::EacFs::Contexts.send(type), -> { application.send("self_#{key}") }]
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
eac_tools-0.76.1 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.76.0 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.75.2 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.75.1 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.75.0 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.74.1 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.74.0 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.73.0 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.72.0 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.70.1 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.70.0 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.69.1 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.69.0 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.68.0 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.67.1 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb
eac_ruby_base0-0.19.0 lib/eac_ruby_base0/runner/contexts.rb
eac_tools-0.67.0 sub/eac_ruby_base0/lib/eac_ruby_base0/runner/contexts.rb