Sha256: 1c71ae05f44c86fd2d5703f2b78b7f9dcd34897ede75d4d4834c206f43299463
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
module Rubber module Util def self.symbolize_keys(map) map.inject({}) do |options, (key, value)| options[key.to_sym || key] = value options end end 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 # Opens the file for writing by root def self.sudo_open(path, perms, &block) open("|sudo tee #{path} > /dev/null", perms, &block) end def self.is_rails? File.exist?(File.join(RUBBER_ROOT, 'config', 'boot.rb')) end def self.is_bundler? File.exist?(File.join(RUBBER_ROOT, 'Gemfile')) end def self.rubber_as_plugin? File.exist?(File.join(RUBBER_ROOT, 'vendor/plugins/rubber')) end 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 def self.fatal(msg, code=1) puts msg exit code end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nirvdrum-rubber-2.0.0.rails3.beta6 | lib/rubber/util.rb |