Class: Ticket::Replicator::FileLoader
- Inherits:
-
Object
- Object
- Ticket::Replicator::FileLoader
- Defined in:
- lib/ticket/replicator/file_loader.rb
Defined Under Namespace
Classes: LoadError
Constant Summary collapse
- FIRST_DATA_ROW_LINE_NUMBER =
2
Instance Attribute Summary collapse
-
#extracted_path ⇒ Object
readonly
Returns the value of attribute extracted_path.
-
#jira_project ⇒ Object
readonly
Returns the value of attribute jira_project.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(jira_project, extracted_path) ⇒ FileLoader
constructor
A new instance of FileLoader.
- #rows ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(jira_project, extracted_path) ⇒ FileLoader
Returns a new instance of FileLoader.
20 21 22 23 |
# File 'lib/ticket/replicator/file_loader.rb', line 20 def initialize(jira_project, extracted_path) @jira_project = jira_project @extracted_path = extracted_path end |
Instance Attribute Details
#extracted_path ⇒ Object (readonly)
Returns the value of attribute extracted_path.
18 19 20 |
# File 'lib/ticket/replicator/file_loader.rb', line 18 def extracted_path @extracted_path end |
#jira_project ⇒ Object (readonly)
Returns the value of attribute jira_project.
18 19 20 |
# File 'lib/ticket/replicator/file_loader.rb', line 18 def jira_project @jira_project end |
Class Method Details
.run_on(jira_project, file_path) ⇒ Object
10 11 12 13 14 |
# File 'lib/ticket/replicator/file_loader.rb', line 10 def self.run_on(jira_project, file_path) log.debug { "Loading #{file_path} into #{jira_project.project_key}..." } new(jira_project, file_path).run end |
Instance Method Details
#rows ⇒ Object
41 42 43 |
# File 'lib/ticket/replicator/file_loader.rb', line 41 def rows CSV.read(extracted_path, headers: true, header_converters: :symbol) end |
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ticket/replicator/file_loader.rb', line 26 def run rows.each_with_index do |row, index| line_number = index + FIRST_DATA_ROW_LINE_NUMBER RowLoader.run_on(jira_project, row) rescue StandardError => e = <<~EOERROR #{extracted_path}:#{line_number}: error while loading row: #{e.}: #{row.inspect} EOERROR raise LoadError, , e.backtrace end end |