Class: Recon::ReconManager
- Inherits:
-
Object
- Object
- Recon::ReconManager
- Defined in:
- lib/ds/recon/recon_manager.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#out_dir ⇒ Object
readonly
Returns the value of attribute out_dir.
-
#source_type ⇒ Object
readonly
Returns the value of attribute source_type.
Instance Method Summary collapse
-
#add_errors(recon_type, messages) ⇒ void
Adds errors to the specified recon type.
-
#errors_for_type(recon_type) ⇒ Array<String>
Returns the list of errors for the specified recon type.
-
#has_errors?(recon_type) ⇒ Boolean
Returns true if errors exist for the specified recon type.
-
#initialize(source_type:, out_dir:, files:) ⇒ void
constructor
Initialize the ReconManager.
-
#recon_builder ⇒ Recon::ReconBuilder
Initializes and returns a new instance of the Recon::ReconBuilder class with the specified output directory, source type, and files.
-
#write_all_csvs ⇒ Array<String>
Write all recon CSV files.
-
#write_csv(recon_type) ⇒ String
Write a CSV file for a specific recon type.
Constructor Details
#initialize(source_type:, out_dir:, files:) ⇒ void
Initialize the ReconManager.
16 17 18 19 20 21 |
# File 'lib/ds/recon/recon_manager.rb', line 16 def initialize source_type:, out_dir:, files: @source_type = source_type @out_dir = out_dir @files = files @errors = {} end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
8 9 10 |
# File 'lib/ds/recon/recon_manager.rb', line 8 def files @files end |
#out_dir ⇒ Object (readonly)
Returns the value of attribute out_dir.
6 7 8 |
# File 'lib/ds/recon/recon_manager.rb', line 6 def out_dir @out_dir end |
#source_type ⇒ Object (readonly)
Returns the value of attribute source_type.
7 8 9 |
# File 'lib/ds/recon/recon_manager.rb', line 7 def source_type @source_type end |
Instance Method Details
#add_errors(recon_type, messages) ⇒ void
This method returns an undefined value.
Adds errors to the specified recon type.
69 70 71 72 73 |
# File 'lib/ds/recon/recon_manager.rb', line 69 def add_errors recon_type, @errors[recon_type.set_name] ||= [] @errors[recon_type.set_name] += nil end |
#errors_for_type(recon_type) ⇒ Array<String>
Returns the list of errors for the specified recon type.
87 88 89 |
# File 'lib/ds/recon/recon_manager.rb', line 87 def errors_for_type recon_type @errors[recon_type.set_name] end |
#has_errors?(recon_type) ⇒ Boolean
Returns true if errors exist for the specified recon type.
79 80 81 |
# File 'lib/ds/recon/recon_manager.rb', line 79 def has_errors? recon_type errors_for_type(recon_type).present? end |
#recon_builder ⇒ Recon::ReconBuilder
Initializes and returns a new instance of the Recon::ReconBuilder class with the specified output directory, source type, and files.
58 59 60 61 62 |
# File 'lib/ds/recon/recon_manager.rb', line 58 def recon_builder @recon_builder ||= Recon::ReconBuilder.new( out_dir: out_dir, source_type: source_type, files: files ) end |
#write_all_csvs ⇒ Array<String>
Write all recon CSV files.
26 27 28 29 30 31 32 |
# File 'lib/ds/recon/recon_manager.rb', line 26 def write_all_csvs outfiles = [] Recon::RECON_TYPES.each do |recon_type| outfiles << write_csv(recon_type) end outfiles end |
#write_csv(recon_type) ⇒ String
Write a CSV file for a specific recon type.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ds/recon/recon_manager.rb', line 38 def write_csv recon_type outfile = File.join out_dir, "#{recon_type.set_name}.csv" CSV.open(outfile, 'w+', headers: true) do |csv| row_num = 0 csv << recon_type.recon_csv_headers recon_builder.each_recon(recon_type.set_name) do |recon| errors = Recon.validate_row(recon_type, recon, row_num: row_num += 1) add_errors recon_type, errors unless errors.blank? csv << recon end end if has_errors?(recon_type) raise DSError, "Error writing #{outfile}:\n#{errors_for_type(recon_type).join("\n")}" end outfile end |