Module: Workarea::DataFile::Operation

Extended by:
ActiveSupport::Concern
Included in:
Export, Import
Defined in:
app/models/workarea/data_file/operation.rb

Instance Method Summary collapse

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'app/models/workarea/data_file/operation.rb', line 48

def complete?
  completed_at.present?
end

#file_typeObject



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

#formatObject



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_typeObject



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_classObject



31
32
33
# File 'app/models/workarea/data_file/operation.rb', line 31

def model_class
  @model_class ||= model_type.constantize
end

#nameObject



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

Raises:

  • (NotImplementedError)


44
45
46
# File 'app/models/workarea/data_file/operation.rb', line 44

def process!
  raise NotImplementedError
end

#sample_file_contentObject



52
53
54
# File 'app/models/workarea/data_file/operation.rb', line 52

def sample_file_content
  format.serialize(samples)
end

#samplesObject



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

#tempfileObject



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