PageRenderTime 65ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/redmine/utils.rb

https://bitbucket.org/prdixit/redmine
Ruby | 55 lines | 30 code | 4 blank | 21 comment | 2 complexity | 6c65ccd0637962bcc7e333b523963912 MD5 | raw file
Possible License(s): GPL-2.0
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. module Redmine
  18. module Utils
  19. class << self
  20. # Returns the relative root url of the application
  21. def relative_url_root
  22. ActionController::Base.respond_to?('relative_url_root') ?
  23. ActionController::Base.relative_url_root.to_s :
  24. ActionController::Base.config.relative_url_root.to_s
  25. end
  26. # Sets the relative root url of the application
  27. def relative_url_root=(arg)
  28. if ActionController::Base.respond_to?('relative_url_root=')
  29. ActionController::Base.relative_url_root=arg
  30. else
  31. ActionController::Base.config.relative_url_root = arg
  32. end
  33. end
  34. # Generates a n bytes random hex string
  35. # Example:
  36. # random_hex(4) # => "89b8c729"
  37. def random_hex(n)
  38. SecureRandom.hex(n)
  39. end
  40. end
  41. module Shell
  42. def shell_quote(str)
  43. if Redmine::Platform.mswin?
  44. '"' + str.gsub(/"/, '\\"') + '"'
  45. else
  46. "'" + str.gsub(/'/, "'\"'\"'") + "'"
  47. end
  48. end
  49. end
  50. end
  51. end