Module: Workarea::DataFile::Operation
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/workarea/data_file/operation.rb
Instance Method Summary collapse
- #complete? ⇒ Boolean
- #file_type ⇒ Object
- #format ⇒ Object
- #mime_type ⇒ Object
- #model_class ⇒ Object
- #name ⇒ Object
- #process! ⇒ Object
- #sample_file_content ⇒ Object
- #samples ⇒ Object
- #tempfile ⇒ Object
Instance Method Details
#complete? ⇒ Boolean
48 49 50 |
# File 'app/models/workarea/data_file/operation.rb', line 48 def complete? completed_at.present? end |
#file_type ⇒ Object
35 36 37 38 |
# File 'app/models/workarea/data_file/operation.rb', line 35 def file_type super.presence_in(Workarea.config.data_file_formats) || Workarea.config.data_file_formats.first end |
#format ⇒ Object
64 65 66 |
# File 'app/models/workarea/data_file/operation.rb', line 64 def format @format ||= "Workarea::DataFile::#{file_type.camelize}".constantize.new(self) end |
#mime_type ⇒ Object
40 41 42 |
# File 'app/models/workarea/data_file/operation.rb', line 40 def mime_type "#{MIME::Types.type_for(file_type).first.to_s}; charset=utf-8" end |
#model_class ⇒ Object
31 32 33 |
# File 'app/models/workarea/data_file/operation.rb', line 31 def model_class @model_class ||= model_type.constantize end |
#name ⇒ Object
27 28 29 |
# File 'app/models/workarea/data_file/operation.rb', line 27 def name model_class.model_name.param_key.titleize end |
#process! ⇒ Object
44 45 46 |
# File 'app/models/workarea/data_file/operation.rb', line 44 def process! raise NotImplementedError end |
#sample_file_content ⇒ Object
52 53 54 |
# File 'app/models/workarea/data_file/operation.rb', line 52 def sample_file_content format.serialize(samples) end |
#samples ⇒ Object
56 57 58 |
# File 'app/models/workarea/data_file/operation.rb', line 56 def samples @samples ||= model_class.limit(Workarea.config.data_file_sample_size).to_a end |
#tempfile ⇒ Object
60 61 62 |
# File 'app/models/workarea/data_file/operation.rb', line 60 def tempfile @tempfile ||= File.open(Pathname.new(Dir.tmpdir).join(generate_file_name), 'w') end |