Module: Redmine::Utils

Defined in:
lib/redmine/utils.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"

46
47
48
# File 'lib/redmine/utils.rb', line 46

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

.relative_url_rootObject

Returns the relative root url of the application


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

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


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

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


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

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