Class: Dumper::Stack
- Inherits:
-
Object
- Object
- Dumper::Stack
- Includes:
- Utility::ObjectFinder
- Defined in:
- lib/dumper/stack.rb
Constant Summary collapse
- DATABASES =
{ :mysql => Dumper::Database::MySQL, :postgresql => Dumper::Database::PostgreSQL, :mongodb => Dumper::Database::MongoDB, :redis => Dumper::Database::Redis, }
Instance Attribute Summary collapse
-
#databases ⇒ Object
Returns the value of attribute databases.
-
#dispatcher ⇒ Object
Returns the value of attribute dispatcher.
-
#framework ⇒ Object
Returns the value of attribute framework.
-
#rackup ⇒ Object
Returns the value of attribute rackup.
-
#rails_env ⇒ Object
Returns the value of attribute rails_env.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Stack
constructor
A new instance of Stack.
- #mongrel? ⇒ Boolean
- #passenger? ⇒ Boolean
- #resque? ⇒ Boolean
-
#supported? ⇒ Boolean
Compatibility.
- #thin? ⇒ Boolean
- #to_hash ⇒ Object
-
#unicorn? ⇒ Boolean
Dispatcher.
- #webrick? ⇒ Boolean
Methods included from Utility::ObjectFinder
#find_instance_in_object_space
Constructor Details
#initialize(options = {}) ⇒ Stack
Returns a new instance of Stack.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/dumper/stack.rb', line 14 def initialize( = {}) @databases = {} # Rackup? @rackup = defined?(Rack::Server) && find_instance_in_object_space(Rack::Server) # Rails? if defined?(::Rails) @framework = :rails @rails_env = Rails.env.to_s @rails_version = Rails::VERSION::STRING @is_supported_rails_version = (::Rails::VERSION::MAJOR >= 3) else @framework = :ruby end if defined?(MongoMapper) MongoMapper.database # Trigger to create a Mongo::DB instance end DATABASES.each do |key, klass| database = klass.new next unless database.set_config_for(@rails_env) || database.set_config_for([:additional_env]) @databases[key] = database end # Which dispatcher? [ :unicorn, :passenger, :thin, :mongrel, :webrick, :resque ].find do |name| @dispatcher = send("#{name}?") ? name : nil end end |
Instance Attribute Details
#databases ⇒ Object
Returns the value of attribute databases.
12 13 14 |
# File 'lib/dumper/stack.rb', line 12 def databases @databases end |
#dispatcher ⇒ Object
Returns the value of attribute dispatcher.
12 13 14 |
# File 'lib/dumper/stack.rb', line 12 def dispatcher @dispatcher end |
#framework ⇒ Object
Returns the value of attribute framework.
12 13 14 |
# File 'lib/dumper/stack.rb', line 12 def framework @framework end |
#rackup ⇒ Object
Returns the value of attribute rackup.
12 13 14 |
# File 'lib/dumper/stack.rb', line 12 def rackup @rackup end |
#rails_env ⇒ Object
Returns the value of attribute rails_env.
12 13 14 |
# File 'lib/dumper/stack.rb', line 12 def rails_env @rails_env end |
Instance Method Details
#mongrel? ⇒ Boolean
75 76 77 78 |
# File 'lib/dumper/stack.rb', line 75 def mongrel? # defined?(::Mongrel::HttpServer) @rackup and @rackup.server.to_s.demodulize == 'Mongrel' end |
#passenger? ⇒ Boolean
66 67 68 |
# File 'lib/dumper/stack.rb', line 66 def passenger? defined?(::Passenger::AbstractServer) || defined?(::IN_PHUSION_PASSENGER) end |
#resque? ⇒ Boolean
85 86 87 |
# File 'lib/dumper/stack.rb', line 85 def resque? defined?(::Resque) && (ENV['QUEUES'] || ENV['QUEUE']) end |
#supported? ⇒ Boolean
Compatibility
57 58 59 |
# File 'lib/dumper/stack.rb', line 57 def supported? @is_supported_rails_version && @dispatcher && !@databases.empty? end |
#thin? ⇒ Boolean
70 71 72 73 |
# File 'lib/dumper/stack.rb', line 70 def thin? defined?(::Thin::Server) && find_instance_in_object_space(::Thin::Server) || (@rackup && @rackup.server.to_s.demodulize == 'Thin') end |
#to_hash ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/dumper/stack.rb', line 46 def to_hash { framework: @framework, rails_env: @rails_env, rails_version: @rails_version, dispatcher: @dispatcher, configs: Hash[@databases.map{|k, database| [ k, database.config.reject{|k,v| k == :password } ] }] } end |
#unicorn? ⇒ Boolean
Dispatcher
62 63 64 |
# File 'lib/dumper/stack.rb', line 62 def unicorn? defined?(::Unicorn::HttpServer) && find_instance_in_object_space(::Unicorn::HttpServer) end |
#webrick? ⇒ Boolean
80 81 82 83 |
# File 'lib/dumper/stack.rb', line 80 def webrick? # defined?(::WEBrick::VERSION) @rackup and @rackup.server.to_s.demodulize == 'WEBrick' end |