--- a/web/app/models/benchmark_batch.rb Thu Oct 30 15:10:12 2014 +0100
+++ b/web/app/models/benchmark_batch.rb Fri Oct 31 17:50:24 2014 +0100
@@ -7,16 +7,18 @@
validates_presence_of :performed_at
def self.archive_directory
- archive_dir = File.join(Rails.root, 'public', 'archive')
+ File.join(Rails.root, "public", "uploads", "archive").tap do |archive_dir|
+ FileUtils.mkdir_p(archive_dir)
+ end
+ end
- Dir.mkdir(archive_dir) unless File.exist? archive_dir
-
- archive_dir
+ def self.for_dashboard
+ includes(benchmark_results: [ :benchmark_durations, :benchmark_info ]).last
end
def self.from_json(data)
batch = BenchmarkBatch.create!(
- benchmark_configuration: BenchmarkConfiguration.from_json(data['configuration']),
+ benchmark_configuration: BenchmarkConfiguration.from_json(data["configuration"]),
performed_at: DateTime.parse(data["timestamp"]),
archive_filename: archive_name_for_data(data))
@@ -47,10 +49,6 @@
batch
end
- def self.for_dashboard
- includes(benchmark_results: [ :benchmark_durations, :benchmark_info ]).last
- end
-
def result_for(info_id)
benchmark_results.find_by(benchmark_info_id: info_id)
end
@@ -61,7 +59,7 @@
# Returns full path to archive file
def archive_path
- File.join(BenchmarkBatch.archive_directory, archive_filename)
+ File.join(self.class.archive_directory, archive_filename)
end
def to_json
@@ -69,11 +67,7 @@
end
def performed_at_ensured
- if performed_at.present?
- performed_at
- else
- Date.today
- end
+ performed_at || Date.today
end
private
@@ -99,6 +93,7 @@
#
# id :integer not null, primary key
# performed_at :datetime
+# archive_filename :text
# created_at :datetime
# updated_at :datetime
# configuration_id :integer