Module: Rubber::Util
- Defined in:
- lib/rubber/util.rb
Class Method Summary collapse
- .is_rails? ⇒ Boolean
- .stringify(val) ⇒ Object
-
.sudo_open(path, perms, &block) ⇒ Object
Opens the file for writing by root.
- .symbolize_keys(map) ⇒ Object
Class Method Details
.is_rails? ⇒ Boolean
32 33 34 |
# File 'lib/rubber/util.rb', line 32 def self.is_rails? File.exist?(File.join(RUBBER_ROOT, 'config', 'environment.rb')) end |
.stringify(val) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rubber/util.rb', line 13 def self.stringify(val) case val when String val when Hash val.inject({}) {|h, a| h[stringify(a[0])] = stringify(a[1]); h} when Enumerable val.collect {|v| stringify(v)} else val.to_s end end |
.sudo_open(path, perms, &block) ⇒ Object
Opens the file for writing by root
28 29 30 |
# File 'lib/rubber/util.rb', line 28 def self.sudo_open(path, perms, &block) open("|sudo tee #{path} > /dev/null", perms, &block) end |
.symbolize_keys(map) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/rubber/util.rb', line 6 def self.symbolize_keys(map) map.inject({}) do |, (key, value)| [key.to_sym || key] = value end end |