Module: Redmine::Utils
- Defined in:
- lib/redmine/utils.rb
Defined Under Namespace
Modules: DateCalculation, Shell
Class Method Summary collapse
-
.random_hex(n) ⇒ Object
Generates a n bytes random hex string Example: random_hex(4) # => “89b8c729”.
-
.relative_url_root ⇒ Object
Returns the relative root url of the application.
-
.relative_url_root=(arg) ⇒ Object
Sets the relative root url of the application.
- .save_upload(upload, path) ⇒ Object
Class Method Details
.random_hex(n) ⇒ Object
Generates a n bytes random hex string Example:
random_hex(4) # => "89b8c729"
42 43 44 |
# File 'lib/redmine/utils.rb', line 42 def random_hex(n) SecureRandom.hex(n) end |
.relative_url_root ⇒ Object
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
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 |