Module: RestFtpDaemon::CommonHelpers

Included in:
Job, JobQueue, Location, Notification, Paginate, Remote::RemoteBase, Remote::RemoteS3
Defined in:
lib/rest-ftp-daemon/helpers/common.rb

Instance Method Summary collapse

Instance Method Details

#dashboard_url(filter = '') ⇒ Object



20
21
22
# File 'lib/rest-ftp-daemon/helpers/common.rb', line 20

def dashboard_url filter = ''
  "#{MOUNT_BOARD}/#{filter}"
end

#exception_to_error(exception) ⇒ Object



32
33
34
# File 'lib/rest-ftp-daemon/helpers/common.rb', line 32

def exception_to_error exception
  underscore 'err_' + exception.class.name.split('::').last
end

#format_bytes(number, unit = "", decimals = 0) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/rest-ftp-daemon/helpers/common.rb', line 4

def format_bytes number, unit="", decimals = 0
  return "Ø" if number.nil? || number.to_f.zero?

  units = ["", "k", "M", "G", "T", "P" ]
  index = ( Math.log(number) / Math.log(2) ).to_i / 10
  converted = number.to_f / (1024 ** index)

  truncated = converted.round(decimals)

  "#{truncated} #{units[index]}#{unit}"
end

#identifier(len) ⇒ Object



16
17
18
# File 'lib/rest-ftp-daemon/helpers/common.rb', line 16

def identifier len
  rand(36**len).to_s(36)
end

#underscore(camel_cased_word) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/rest-ftp-daemon/helpers/common.rb', line 24

def underscore camel_cased_word
  camel_cased_word.to_s.gsub(/::/, '/').
    gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').
    tr("-", "_").
    downcase
end