Class: AssLauncher::Cmd::Abstract::Cli::Report Private

Inherits:
Object
  • Object
show all
Defined in:
lib/ass_launcher/cmd.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Reporter rubocop:disable Metrics/ClassLength

Defined Under Namespace

Classes: Row

Constant Summary collapse

USAGE_COLUMNS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[:usage,
:argument,
:parent,
:group,
:desc].freeze
DEVEL_COLUMNS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

[:parameter,
:dsl_method,
:accepted_values,
:parent,
:param_klass,
:group,
:require,
:desc].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, mode, version, appiared_only, query, dev_mode) ⇒ Report

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Metrics/ParameterLists



608
609
610
611
612
613
614
615
# File 'lib/ass_launcher/cmd.rb', line 608

def initialize(client, mode, version, appiared_only, query, dev_mode)
  @client = client
  @mode = mode
  @version = version
  @appiared_only = appiared_only
  @query = query
  @dev_mode = dev_mode
end

Instance Attribute Details

#appiared_onlyObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



605
606
607
# File 'lib/ass_launcher/cmd.rb', line 605

def appiared_only
  @appiared_only
end

#clientObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



605
606
607
# File 'lib/ass_launcher/cmd.rb', line 605

def client
  @client
end

#dev_modeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



605
606
607
# File 'lib/ass_launcher/cmd.rb', line 605

def dev_mode
  @dev_mode
end

#modeObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



605
606
607
# File 'lib/ass_launcher/cmd.rb', line 605

def mode
  @mode
end

#queryObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



605
606
607
# File 'lib/ass_launcher/cmd.rb', line 605

def query
  @query
end

#versionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



605
606
607
# File 'lib/ass_launcher/cmd.rb', line 605

def version
  @version
end

Instance Method Details

#clients?(p) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable Metrics/ParameterLists

Returns:

  • (Boolean)


618
619
620
# File 'lib/ass_launcher/cmd.rb', line 618

def clients?(p)
  p.binary_matcher.clients.include? client
end

#coll_match?(prop, p) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


645
646
647
# File 'lib/ass_launcher/cmd.rb', line 645

def coll_match?(prop, p)
  !(p.send(prop).to_s =~ query).nil?
end

#columns_width(columns, rows) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable Style/ConditionalAssignment



702
703
704
705
706
707
708
709
710
711
712
713
# File 'lib/ass_launcher/cmd.rb', line 702

def columns_width(columns, rows)
  total = columns.size + 1
  columns.each_with_object({}) do |col, r|
    total -= 1
    if [:usage, :parameter, :dsl_method].include? col
      r[col] = max_col_width(col, rows)
    else
      r[col] = eval_width(col, total, r,
                          4 + (columns.size - 1) * 3, rows)
    end
  end
end

#eval_width(col, total, r, trim, rows) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



696
697
698
699
# File 'lib/ass_launcher/cmd.rb', line 696

def eval_width(col, total, r, trim, rows)
  [(term_width(trim) - r.values.inject(0) { |i, o| o + i }) / total,
   max_col_width(col, rows)].min
end

#executeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



678
679
680
681
682
683
# File 'lib/ass_launcher/cmd.rb', line 678

def execute
  r = select_parameters.map do |p|
    Row.new(p)
  end
  r.sort_by { |row| row.param.full_name }
end

#filter_headerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable Style/ConditionalAssignment



727
728
729
# File 'lib/ass_launcher/cmd.rb', line 727

def filter_header
  "FILTERED BY: #{query}" if query
end

#grouped_rowsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



653
654
655
656
657
658
659
660
# File 'lib/ass_launcher/cmd.rb', line 653

def grouped_rows
  r = {}
  groups.each do |gname, _|
    r[gname] = rows.select { |row| row.group == gname }
      .sort_by { |row| row.param.full_name }
  end
  r
end

#groupsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



649
650
651
# File 'lib/ass_launcher/cmd.rb', line 649

def groups
  AssLauncher::Enterprise::Cli::CliSpec.cli_def.parameters_groups
end

#main_headerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



715
716
717
718
719
720
721
722
723
724
# File 'lib/ass_launcher/cmd.rb', line 715

def main_header
  if dev_mode
    r = 'DSL METHODS'
  else
    r = 'CLI PARAMETERS'
  end
  r << " AVAILABLE FOR: \"#{client}\" CLIENT V#{version}"
  r << " IN \"#{mode}\" RUNNING MODE" if client == :thick
  r.upcase
end

#match?(p) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


635
636
637
# File 'lib/ass_launcher/cmd.rb', line 635

def match?(p)
  clients?(p) && modes?(p) && version?(p)
end

#max_col_width(col, rows) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



685
686
687
688
689
# File 'lib/ass_launcher/cmd.rb', line 685

def max_col_width(col, rows)
  [rows.map do |r|
    r.send(col).to_s.length
  end.max, col.to_s.length].max
end

#modes?(p) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


622
623
624
# File 'lib/ass_launcher/cmd.rb', line 622

def modes?(p)
  p.modes.include? mode
end

#not_filtred?(p) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


639
640
641
642
643
# File 'lib/ass_launcher/cmd.rb', line 639

def not_filtred?(p)
  return true unless query
  coll_match?(:desc, p) || coll_match?(:parent, p) || \
    coll_match?(:name, p)
end

#rowsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



662
663
664
# File 'lib/ass_launcher/cmd.rb', line 662

def rows
  @rows ||= execute
end

#select_parametersObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



666
667
668
669
670
671
672
673
674
675
676
# File 'lib/ass_launcher/cmd.rb', line 666

def select_parameters
  r = []
  AssLauncher::Enterprise::Cli::CliSpec
    .cli_def.parameters.parameters.each do |p|
    if match?(p) && not_filtred?(p)
      r << p
      r << p.parent if p.parent && !r.include?(p.parent)
    end
  end
  r
end

#term_width(trim = 0) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



692
693
694
# File 'lib/ass_launcher/cmd.rb', line 692

def term_width(trim = 0)
  IO.console.winsize[1] - trim
end

#to_csv(columns) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:enable all



768
769
770
771
772
773
774
775
# File 'lib/ass_launcher/cmd.rb', line 768

def to_csv(columns)
  r = "#{columns.join(';')}\n"
  rows.each do |row|
    r << row.to_csv(columns)
    r << "\n"
  end
  r
end

#to_table(columns) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable all @doto: refactoring and tests require



733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File 'lib/ass_launcher/cmd.rb', line 733

def to_table(columns)
  require 'command_line_reporter'
  extend CommandLineReporter

  header title: main_header, width: main_header.length, rule: true,
         align: 'center', bold: true, spacing: 0

  header title: filter_header, width: filter_header.length, rule: true,
         align: 'center', bold: false, color: 'yellow', spacing: 0 if\
         filter_header

  grouped_rows.each do |gname, rows|
    next if rows.size.zero?
    table(border: true, encoding: :ascii) do
      header title: "PARAMTERS GROUP: \"#{groups[gname][:desc]}\"",
        bold: true

      row header: true do
        columns_width(columns, rows).each do |col, width|
          column(col.upcase, width:  width)
        end
      end
      rows.each do |row_|
        row do
          columns.each do |col|
            column(row_.send(col))
          end
        end
      end
    end
  end
  nil
end

#version?(p) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


626
627
628
629
630
631
632
633
# File 'lib/ass_launcher/cmd.rb', line 626

def version?(p)
  return true if version.nil?
  if appiared_only
    p.binary_matcher.requirement.to_s =~ /^>=\s*#{version}/
  else
    p.match_version?(version) unless appiared_only
  end
end