diff options
| author | Luc Donnet | 2015-04-27 17:35:34 +0200 |
|---|---|---|
| committer | Luc Donnet | 2015-04-27 17:35:34 +0200 |
| commit | abdfb2c468c6267bcf3cdc335faa05132e5a6a2a (patch) | |
| tree | 49bb9437ff26e81e5341d07ccbe7db79aed15541 | |
| parent | 743a159c42b1f0814365ce7182c4a5e5f01be9bf (diff) | |
| download | chouette-core-abdfb2c468c6267bcf3cdc335faa05132e5a6a2a.tar.bz2 | |
Refactor import and export report to use concern
| -rw-r--r-- | app/controllers/concerns/.keep | 0 | ||||
| -rw-r--r-- | app/models/concerns/.keep | 0 | ||||
| -rw-r--r-- | app/models/concerns/report_concern.rb | 142 | ||||
| -rw-r--r-- | app/models/export_report.rb | 129 | ||||
| -rw-r--r-- | app/models/import_report.rb | 136 |
5 files changed, 145 insertions, 262 deletions
diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/app/controllers/concerns/.keep diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/app/models/concerns/.keep diff --git a/app/models/concerns/report_concern.rb b/app/models/concerns/report_concern.rb new file mode 100644 index 000000000..52e135951 --- /dev/null +++ b/app/models/concerns/report_concern.rb @@ -0,0 +1,142 @@ +module ReportConcern + extend ActiveSupport::Concern + extend ActiveModel::Naming + extend ActiveModel::Translation + include ActiveModel::Model + + included do + attr_reader :datas + end + + module ClassMethods + end + + def initialize( response ) + @datas = response.action_report + end + + def current_level + datas.progression.current_step if datas.progression + end + + def last_step + datas.progression.steps.last if datas.progression + end + + def current_step_name + last_step.step if last_step + end + + def current_step + last_step.realized if last_step + end + + def total_steps + last_step.total if last_step + end + + def zip_file + datas.zip_file + end + + def files + datas.files || [] + end + + def error_files + files.select{ |file| file[:status] == "ERROR"} + end + + def ignored_files + files.select{ |file| file[:status] == "IGNORED"} + end + + def ok_files + files.select{ |file| file[:status] == "OK"} + end + + def line_items + [].tap do |line_items| + datas.lines.each do |line| + line_items << LineItem.new(line) + end if datas.lines? + end + end + + def stats + datas.stats + end + + def lines + stats.present? ? stats.line_count : 0 + end + + def routes + stats.present? ? stats.route_count : 0 + end + + def connection_links + stats.present? ? stats.connection_link_count : 0 + end + + def time_tables + stats.present? ? stats.time_table_count : 0 + end + + def stop_areas + stats.present? ? stats.stop_area_count : 0 + end + + def access_points + stats.present? ? stats.access_point_count : 0 + end + + def vehicle_journeys + stats.present? ? stats.vehicle_journey_count : 0 + end + + def journey_patterns + stats.present? ? stats.journey_pattern_count : 0 + end + + + class LineItem + attr_reader :name, :status, :stats + + def initialize( options = Hashie::Mash.new ) + @name = options.name if options.name? + @status = options.status if options.status? + @stats = options.stats if options.stats? + end + + def routes + stats.route_count + end + + def connection_links + stats.connection_link_count + end + + def time_tables + stats.time_table_count + end + + def stop_areas + stats.stop_area_count + end + + def access_points + stats.access_point_count + end + + def vehicle_journeys + stats.vehicle_journey_count + end + + def journey_patterns + stats.journey_pattern_count + end + + end + +end diff --git a/app/models/export_report.rb b/app/models/export_report.rb index 916b6020a..9fd7974c2 100644 --- a/app/models/export_report.rb +++ b/app/models/export_report.rb @@ -1,132 +1,5 @@ class ExportReport - extend ActiveModel::Naming - extend ActiveModel::Translation - include ActiveModel::Model - - attr_reader :datas - - def initialize(response) - @datas = response.action_report - end - - def current_level - datas.progression.current_step if datas.progression - end - - def last_step - datas.progression.steps.last if datas.progression - end - - def current_step_name - last_step.step if last_step - end - - def current_step - last_step.realized if last_step - end - - def total_steps - last_step.total if last_step - end - - def files - datas.files || [] - end - - def error_files - files.select{ |file| file[:status] == "ERROR"} - end - - def ignored_files - files.select{ |file| file[:status] == "IGNORED"} - end - - def ok_files - files.select{ |file| file[:status] == "OK"} - end - - def line_items - [].tap do |line_items| - datas.lines.each do |line| - line_items << LineItem.new(line) - end if datas.lines? - end - end - - def stats - datas.stats - end - - def lines - stats.present? ? stats.line_count : 0 - end - - def routes - stats.present? ? stats.route_count : 0 - end - - def connection_links - stats.present? ? stats.connection_link_count : 0 - end - - def time_tables - stats.present? ? stats.time_table_count : 0 - end - - def stop_areas - stats.present? ? stats.stop_area_count : 0 - end - - def access_points - stats.present? ? stats.access_point_count : 0 - end - - def vehicle_journeys - stats.present? ? stats.vehicle_journey_count : 0 - end - - def journey_patterns - stats.present? ? stats.journey_pattern_count : 0 - end - - class LineItem - attr_reader :name, :status, :stats - - def initialize( options = {} ) - @name = options.name if options.name? - @status = options.status if options.status? - @stats = options.stats if options.stats? - end - - def routes - stats.route_count - end - - def connection_links - stats.connection_link_count - end - - def time_tables - stats.time_table_count - end - - def stop_areas - stats.stop_area_count - end - - def access_points - stats.access_point_count - end - - def vehicle_journeys - stats.vehicle_journey_count - end - - def journey_patterns - stats.journey_pattern_count - end - - end + include ReportConcern end diff --git a/app/models/import_report.rb b/app/models/import_report.rb index ed40f1b61..42baf8c00 100644 --- a/app/models/import_report.rb +++ b/app/models/import_report.rb @@ -1,137 +1,5 @@ -class ImportReport - extend ActiveModel::Naming - extend ActiveModel::Translation - include ActiveModel::Model - - attr_reader :datas - - def initialize( response ) - @datas = response.action_report - end - - def current_level - datas.progression.current_step if datas.progression - end - - def last_step - datas.progression.steps.last if datas.progression - end - - def current_step_name - last_step.step if last_step - end - - def current_step - last_step.realized if last_step - end - - def total_steps - last_step.total if last_step - end - - def zip_file - datas.zip_file - end - - def files - datas.files || [] - end - - def error_files - files.select{ |file| file[:status] == "ERROR"} - end - - def ignored_files - files.select{ |file| file[:status] == "IGNORED"} - end - - def ok_files - files.select{ |file| file[:status] == "OK"} - end - - def line_items - [].tap do |line_items| - datas.lines.each do |line| - line_items << LineItem.new(line) - end if datas.lines? - end - end - - def stats - datas.stats - end - - def lines - stats.present? ? stats.line_count : 0 - end - - def routes - stats.present? ? stats.route_count : 0 - end - - def connection_links - stats.present? ? stats.connection_link_count : 0 - end - - def time_tables - stats.present? ? stats.time_table_count : 0 - end - - def stop_areas - stats.present? ? stats.stop_area_count : 0 - end - - def access_points - stats.present? ? stats.access_point_count : 0 - end - - def vehicle_journeys - stats.present? ? stats.vehicle_journey_count : 0 - end - - def journey_patterns - stats.present? ? stats.journey_pattern_count : 0 - end - - - class LineItem - attr_reader :name, :status, :stats - - def initialize( options = Hashie::Mash.new ) - @name = options.name if options.name? - @status = options.status if options.status? - @stats = options.stats if options.stats? - end - - def routes - stats.route_count - end - - def connection_links - stats.connection_link_count - end - - def time_tables - stats.time_table_count - end - - def stop_areas - stats.stop_area_count - end - - def access_points - stats.access_point_count - end - - def vehicle_journeys - stats.vehicle_journey_count - end - - def journey_patterns - stats.journey_pattern_count - end - - end +class ImportReport + include ReportConcern end |
