Module: Redmine::Utils

Defined in:
lib/redmine/utils.rb,
lib/redmine/utils/shell.rb,
lib/redmine/utils/date_calculation.rb

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"


48
49
50
# File 'lib/redmine/utils.rb', line 48

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

.relative_url_rootObject

Returns the relative root url of the application



28
29
30
31
32
33
34
# File 'lib/redmine/utils.rb', line 28

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

.relative_url_root=(arg) ⇒ Object

Sets the relative root url of the application



37
38
39
40
41
42
43
# File 'lib/redmine/utils.rb', line 37

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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/redmine/utils.rb', line 52

def save_upload(upload, path)
  directory = File.dirname(path)
  unless File.exist?(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