Module: Redmine::Utils

Defined in:
lib/redmine/utils.rb

Overview

Since:

  • 0.8.2

Defined Under Namespace

Modules: DateCalculation, Shell

Class Method Summary collapse

Class Method Details

.random_hex(n) ⇒ Object

Generates a n bytes random hex string Example:

random_hex(4) # => "89b8c729"

Since:

  • 1.4.0



42
43
44
# File 'lib/redmine/utils.rb', line 42

def random_hex(n)
  SecureRandom.hex(n)
end

.relative_url_rootObject

Returns the relative root url of the application



24
25
26
27
28
# File 'lib/redmine/utils.rb', line 24

def relative_url_root
  ActionController::Base.respond_to?('relative_url_root') ?
    ActionController::Base.relative_url_root.to_s :
    ActionController::Base.config.relative_url_root.to_s
end

.relative_url_root=(arg) ⇒ Object

Sets the relative root url of the application



31
32
33
34
35
36
37
# File 'lib/redmine/utils.rb', line 31

def relative_url_root=(arg)
  if ActionController::Base.respond_to?('relative_url_root=')
    ActionController::Base.relative_url_root=arg
  else
    ActionController::Base.config.relative_url_root = arg
  end
end

.save_upload(upload, path) ⇒ Object

Since:

  • 3.2.0



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/redmine/utils.rb', line 46

def save_upload(upload, path)
  directory = File.dirname(path)
  unless File.exists?(directory)
    FileUtils.mkdir_p directory
  end
  File.open(path, "wb") do |f|
    if upload.respond_to?(:read)
      buffer = ""
      while (buffer = upload.read(8192))
        f.write(buffer)
        yield buffer if block_given?
      end
    else
      f.write(upload)
      yield upload if block_given?
    end
  end
end