mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 19:48:08 +00:00
Initial Commit
Co-authored-by: Subin <subinthattaparambil@gmail.com> Co-authored-by: Manoj <manojmj92@gmail.com> Co-authored-by: Nithin <webofnithin@gmail.com>
This commit is contained in:
38
lib/local_resource.rb
Normal file
38
lib/local_resource.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
class LocalResource
|
||||
attr_reader :uri
|
||||
|
||||
def initialize(uri)
|
||||
@uri = uri
|
||||
end
|
||||
|
||||
def file
|
||||
@file ||= Tempfile.new(tmp_filename, tmp_folder, encoding: encoding).tap do |f|
|
||||
io.rewind
|
||||
f.write(io.read)
|
||||
f.close
|
||||
end
|
||||
end
|
||||
|
||||
def io
|
||||
@io ||= uri.open
|
||||
end
|
||||
|
||||
def encoding
|
||||
io.rewind
|
||||
io.read.encoding
|
||||
end
|
||||
|
||||
def tmp_filename
|
||||
[
|
||||
Time.now.to_i.to_s,
|
||||
Pathname.new(uri.path).extname
|
||||
]
|
||||
end
|
||||
|
||||
def tmp_folder
|
||||
# If we're using Rails:
|
||||
Rails.root.join('tmp')
|
||||
# Otherwise:
|
||||
# '/wherever/you/want'
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user