Sha256: f22d625d5a45133a3fbd24316fa4d6eb2699ad3f947949117b198844bf879ba9

Contents?: true

Size: 1.97 KB

Versions: 75

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

require 'avm/tools/core_ext'

module Avm
  module Tools
    class Runner
      class Source < ::Avm::Sources::Runner
        class Subs
          PADDING = '  '

          runner_with :help, :output do
            desc 'Output source\'s subs.'
            bool_opt '-i', '--info'
            bool_opt '-R', '--recursive'
            bool_opt '-t', '--tree'
          end

          def run
            start_banner
            run_output
          end

          def start_banner
            infov 'Include PATH', runner_context.call(:subject).subs_include_path
            infov 'Exclude PATH', runner_context.call(:subject).subs_exclude_path
            infov 'Count', runner_context.call(:subject).subs.count
          end

          def output_content
            b = []
            runner_context.call(:subject).subs.each do |sub|
              b += sub_output_content_lines(sub, 0)
            end
            b.map { |line| "#{line}\n" }.join
          end

          def sub_info_label(sub)
            return '' unless parsed.info?

            ' [' + {
              'CLASS' => sub.class.name,
              'SCM' => sub.scm.class.name
            }.map { |k, v| "#{k}: #{v}" }.join(', ') + ']'
          end

          def sub_label(sub, level)
            sub_self_label(sub, level) + sub_info_label(sub)
          end

          def sub_self_label(sub, level)
            if parsed.tree?
              (PADDING * level) + sub.relative_path.to_s
            else
              sub.path.relative_path_from(runner_context.call(:subject).path).to_s
            end
          end

          def sub_output_content_lines(sub, level)
            [sub_label(sub, level)] + sub_subs_output_content_lines(sub, level)
          end

          def sub_subs_output_content_lines(sub, level)
            return [] unless parsed.recursive?

            sub.subs.flat_map { |sub_sub| sub_output_content_lines(sub_sub, level + 1) }
          end
        end
      end
    end
  end
end

Version data entries

75 entries across 75 versions & 2 rubygems

Version Path
eac_tools-0.85.1 sub/avm-tools/lib/avm/tools/runner/source/subs.rb
avm-tools-0.159.1 lib/avm/tools/runner/source/subs.rb
eac_tools-0.85.0 sub/avm-tools/lib/avm/tools/runner/source/subs.rb
eac_tools-0.84.2 sub/avm-tools/lib/avm/tools/runner/source/subs.rb
eac_tools-0.84.1 sub/avm-tools/lib/avm/tools/runner/source/subs.rb
eac_tools-0.84.0 sub/avm-tools/lib/avm/tools/runner/source/subs.rb
eac_tools-0.83.0 sub/avm-tools/lib/avm/tools/runner/source/subs.rb
avm-tools-0.159.0 lib/avm/tools/runner/source/subs.rb
eac_tools-0.82.0 sub/avm-tools/lib/avm/tools/runner/source/subs.rb
avm-tools-0.158.0 lib/avm/tools/runner/source/subs.rb
eac_tools-0.81.0 sub/avm-tools/lib/avm/tools/runner/source/subs.rb
eac_tools-0.80.0 sub/avm-tools/lib/avm/tools/runner/source/subs.rb
avm-tools-0.157.0 lib/avm/tools/runner/source/subs.rb
eac_tools-0.79.0 sub/avm-tools/lib/avm/tools/runner/source/subs.rb
avm-tools-0.156.0 lib/avm/tools/runner/source/subs.rb
eac_tools-0.78.0 sub/avm-tools/lib/avm/tools/runner/source/subs.rb
eac_tools-0.77.1 sub/avm-tools/lib/avm/tools/runner/source/subs.rb
avm-tools-0.155.0 lib/avm/tools/runner/source/subs.rb
eac_tools-0.77.0 sub/avm-tools/lib/avm/tools/runner/source/subs.rb
eac_tools-0.76.1 sub/avm-tools/lib/avm/tools/runner/source/subs.rb