Class: S3Relay::Upload

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
app/models/s3_relay/upload.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.importedObject



33
34
35
# File 'app/models/s3_relay/upload.rb', line 33

def self.imported
  where(state: "imported")
end

.pendingObject



29
30
31
# File 'app/models/s3_relay/upload.rb', line 29

def self.pending
  where(state: "pending")
end

Instance Method Details

#as_json(options = { }) ⇒ Object



75
76
77
78
79
80
# File 'app/models/s3_relay/upload.rb', line 75

def as_json(options = { })
  h = super(options)
  h[:public_url] = public_url
  h[:public_url_500x500] = public_url_500x500
  h
end

#imported?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/s3_relay/upload.rb', line 41

def imported?
  state == "imported"
end

#mark_imported!Object



45
46
47
# File 'app/models/s3_relay/upload.rb', line 45

def mark_imported!
  update_attributes(state: "imported", imported_at: Time.now)
end

#notify_parentObject



49
50
51
52
53
54
55
# File 'app/models/s3_relay/upload.rb', line 49

def notify_parent
  return unless parent.present?

  if parent.respond_to?(:import_upload)
    parent.import_upload(id)
  end
end

#pending?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'app/models/s3_relay/upload.rb', line 37

def pending?
  state == "pending"
end

#private_urlObject



71
72
73
# File 'app/models/s3_relay/upload.rb', line 71

def private_url
  S3Relay::PrivateUrl.new(uuid, filename).generate
end

#public_urlObject



57
58
59
# File 'app/models/s3_relay/upload.rb', line 57

def public_url
  S3Relay::PrivateUrl.new(uuid, filename).public_url
end

#public_url_500x500Object



61
62
63
64
# File 'app/models/s3_relay/upload.rb', line 61

def public_url_500x500
  file_full_s3_key = public_url.split('amazonaws.com/')[1]
  "http://epartrade.s3-website-us-west-1.amazonaws.com/500x500/#{file_full_s3_key}"
end

#public_url_with_size(size) ⇒ Object



66
67
68
69
# File 'app/models/s3_relay/upload.rb', line 66

def public_url_with_size size
  file_full_s3_key = public_url.split('amazonaws.com/')[1]
  "http://epartrade.s3-website-us-west-1.amazonaws.com/#{size}/#{file_full_s3_key}"
end