Class: Attachinary::File

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/attachinary/file.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.upload!(file) ⇒ Object



27
28
29
30
31
32
# File 'app/models/attachinary/file.rb', line 27

def self.upload!(file)
  if file.respond_to?(:read)
    response = Cloudinary::Uploader.upload(file, tags: "env_#{Rails.env}")
    create! response.slice('public_id', 'version', 'width', 'height', 'format', 'resource_type')
  end
end

Instance Method Details

#as_json(options) ⇒ Object



9
10
11
# File 'app/models/attachinary/file.rb', line 9

def as_json(options)
  super(only: [:id, :public_id, :format, :version, :resource_type], methods: [:path])
end

#fullpath(options = {}) ⇒ Object



22
23
24
25
# File 'app/models/attachinary/file.rb', line 22

def fullpath(options={})
  format = options.delete(:format)
  Cloudinary::Utils.cloudinary_url(path(format), options)
end

#path(custom_format = nil) ⇒ Object



13
14
15
16
17
18
19
20
# File 'app/models/attachinary/file.rb', line 13

def path(custom_format=nil)
  p = "v#{version}/#{public_id}"
  if resource_type == 'image' && custom_format != false
    custom_format ||= format
    p<< ".#{custom_format}"
  end
  p
end