You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/libs/util.rb

36 lines
902 B

module Util
module_function
def days_between(time, other_time)
raise ArgumentError if time.blank? || other_time.blank?
Date.parse(time.to_s) - Date.parse(other_time.to_s)
end
def convert_base64_image(str, **opts)
return if str.blank?
Base64ImageConverter.new(**opts).convert(str)
end
def write_file(io, path)
dir = File.dirname(path)
FileUtils.mkdir_p(dir) unless File.directory?(dir)
Rails.logger.info("### save file #{path}, size: #{io.size} ~")
File.open(path, 'wb') do |file|
if io.respond_to?(:read)
io.rewind
while buffer = io.read(8192)
file.write(buffer)
end
else
file.write(io)
end
end
end
def logger_error(exception)
Rails.logger.error(exception.message)
exception.backtrace.each { |message| Rails.logger.error(message) }
end
end