Sha256: a04a50bc58c4e1c85e31a37747214281a279f54cd02423f9aa3876830767341e

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

class EventExportFile < ActiveRecord::Base
  include Statesman::Adapters::ActiveRecordModel
  include ExportFile
  enju_export_file_model
  has_attached_file :event_export
  validates_attachment_content_type :event_export, :content_type => /\Atext\/plain\Z/
  has_many :event_export_file_transitions

  def state_machine
    EventExportFileStateMachine.new(self, transition_class: EventExportFileTransition)
  end

  delegate :can_transition_to?, :transition_to!, :transition_to, :current_state,
    to: :state_machine

  def export!
    transition_to!(:started)
    tempfile = Tempfile.new(['event_export_file_', '.txt'])
    file = Event.export(format: :txt)
    tempfile.puts(file)
    tempfile.close
    self.event_export = File.new(tempfile.path, "r")
    if save
      send_message
    end
    transition_to!(:completed)
  rescue => e
    transition_to!(:failed)
    raise e
  end

  private
  def self.transition_class
    EventExportFileTransition
  end
end

# == Schema Information
#
# Table name: event_export_files
#
#  id                        :integer          not null, primary key
#  user_id                   :integer
#  event_export_file_name    :string(255)
#  event_export_content_type :string(255)
#  event_export_file_size    :integer
#  event_export_updated_at   :datetime
#  executed_at               :datetime
#  created_at                :datetime         not null
#  updated_at                :datetime         not null
#

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
enju_event-0.1.17.pre20 app/models/event_export_file.rb
enju_event-0.1.17.pre19 app/models/event_export_file.rb