Module: Rubber::Util
- Defined in:
- lib/rubber/util.rb
Class Method Summary collapse
- .fatal(msg, code = 1) ⇒ Object
- .is_bundler? ⇒ Boolean
- .is_rails2? ⇒ Boolean
- .is_rails3? ⇒ Boolean
- .is_rails? ⇒ Boolean
- .prompt(name, desc, required = false, default = nil) ⇒ Object
- .rubber_as_plugin? ⇒ Boolean
- .stringify(val) ⇒ Object
-
.sudo_open(path, perms, &block) ⇒ Object
Opens the file for writing by root.
- .symbolize_keys(map) ⇒ Object
Class Method Details
.fatal(msg, code = 1) ⇒ Object
66 67 68 69 |
# File 'lib/rubber/util.rb', line 66 def self.fatal(msg, code=1) puts msg exit code end |
.is_bundler? ⇒ Boolean
44 45 46 |
# File 'lib/rubber/util.rb', line 44 def self.is_bundler? File.exist?(File.join(RUBBER_ROOT, 'Gemfile')) end |
.is_rails2? ⇒ Boolean
36 37 38 |
# File 'lib/rubber/util.rb', line 36 def self.is_rails2? defined?(Rails) && defined?(Rails::VERSION) && Rails::VERSION::MAJOR == 2 end |
.is_rails3? ⇒ Boolean
40 41 42 |
# File 'lib/rubber/util.rb', line 40 def self.is_rails3? defined?(Rails) && defined?(Rails::VERSION) && Rails::VERSION::MAJOR == 3 end |
.is_rails? ⇒ Boolean
32 33 34 |
# File 'lib/rubber/util.rb', line 32 def self.is_rails? File.exist?(File.join(RUBBER_ROOT, 'config', 'boot.rb')) end |
.prompt(name, desc, required = false, default = nil) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rubber/util.rb', line 52 def self.prompt(name, desc, required=false, default=nil) value = ENV.delete(name) msg = "#{desc}" msg << " [#{default}]" if default msg << ": " unless value print msg value = gets end value = value.size == 0 ? default : value self.fatal "#{name} is required, pass using environment or enter at prompt" if required && ! value return value end |
.rubber_as_plugin? ⇒ Boolean
48 49 50 |
# File 'lib/rubber/util.rb', line 48 def self.rubber_as_plugin? File.exist?(File.join(RUBBER_ROOT, 'vendor/plugins/rubber')) 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 |