Sha256: a288533492d4fe116ed5aa19389aec22ac7640eadec0bcfe584994d8189f7f99

Contents?: true

Size: 1.89 KB

Versions: 6

Compression:

Stored size: 1.89 KB

Contents

class EventExportFile < ActiveRecord::Base
  include Statesman::Adapters::ActiveRecordQueries
  include ExportFile
  enju_export_file_model

  if ENV['ENJU_STORAGE'] == 's3'
    has_attached_file :event_export, storage: :s3,
      s3_credentials: {
        access_key: ENV['AWS_ACCESS_KEY_ID'],
        secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
        bucket: ENV['S3_BUCKET_NAME'],
        s3_host_name: ENV['S3_HOST_NAME']
      },
      s3_permissions: :private
  else
    has_attached_file :event_export,
      path: ":rails_root/private/system/:class/:attachment/:id_partition/:style/:filename"
  end
  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

  def self.initial_state
    :pending
  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

6 entries across 6 versions & 1 rubygems

Version Path
enju_event-0.1.19 app/models/event_export_file.rb
enju_event-0.1.18 app/models/event_export_file.rb
enju_event-0.1.17 app/models/event_export_file.rb
enju_event-0.1.17.pre27 app/models/event_export_file.rb
enju_event-0.1.17.pre26 app/models/event_export_file.rb
enju_event-0.1.17.pre25 app/models/event_export_file.rb