lib/rubber/util.rb in rubber-1.3.2 vs lib/rubber/util.rb in rubber-1.5.0

- old
+ new

@@ -28,10 +28,45 @@ 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', 'environment.rb')) + File.exist?(File.join(RUBBER_ROOT, 'config', 'boot.rb')) end + def self.is_rails2? + defined?(Rails) && defined?(Rails::VERSION) && Rails::VERSION::MAJOR == 2 + end + + def self.is_rails3? + defined?(Rails) && defined?(Rails::VERSION) && Rails::VERSION::MAJOR == 3 + 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