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, :mongodb => Dumper::Database::MongoDB, :redis => Dumper::Database::Redis, }
Instance Attribute Summary collapse
-
#configs ⇒ Object
Returns the value of attribute configs.
-
#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 ⇒ 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 ⇒ Stack
Returns a new instance of Stack.
13 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 |
# File 'lib/dumper/stack.rb', line 13 def initialize @configs = {} # Rackup? @rackup = 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) DATABASES.each do |key, klass| next unless config = klass.new.config_for(@rails_env) @configs[key] = config end else @framework = :ruby end # Which dispatcher? [ :unicorn, :passenger, :thin, :mongrel, :webrick, :resque ].find do |name| @dispatcher = send("#{name}?") ? name : nil end end |
Instance Attribute Details
#configs ⇒ Object
Returns the value of attribute configs.
11 12 13 |
# File 'lib/dumper/stack.rb', line 11 def configs @configs end |
#dispatcher ⇒ Object
Returns the value of attribute dispatcher.
11 12 13 |
# File 'lib/dumper/stack.rb', line 11 def dispatcher @dispatcher end |
#framework ⇒ Object
Returns the value of attribute framework.
11 12 13 |
# File 'lib/dumper/stack.rb', line 11 def framework @framework end |
#rackup ⇒ Object
Returns the value of attribute rackup.
11 12 13 |
# File 'lib/dumper/stack.rb', line 11 def rackup @rackup end |
#rails_env ⇒ Object
Returns the value of attribute rails_env.
11 12 13 |
# File 'lib/dumper/stack.rb', line 11 def rails_env @rails_env end |
Instance Method Details
#mongrel? ⇒ Boolean
69 70 71 72 |
# File 'lib/dumper/stack.rb', line 69 def mongrel? # defined?(::Mongrel::HttpServer) @rackup and @rackup.server.to_s.demodulize == 'Mongrel' end |
#passenger? ⇒ Boolean
60 61 62 |
# File 'lib/dumper/stack.rb', line 60 def passenger? defined?(::Passenger::AbstractServer) || defined?(::IN_PHUSION_PASSENGER) end |
#resque? ⇒ Boolean
79 80 81 |
# File 'lib/dumper/stack.rb', line 79 def resque? defined?(::Resque) && (ENV['QUEUES'] || ENV['QUEUE']) end |
#supported? ⇒ Boolean
Compatibility
51 52 53 |
# File 'lib/dumper/stack.rb', line 51 def supported? @is_supported_rails_version && @dispatcher && !@configs.empty? end |
#thin? ⇒ Boolean
64 65 66 67 |
# File 'lib/dumper/stack.rb', line 64 def thin? defined?(::Thin::Server) && find_instance_in_object_space(::Thin::Server) || (@rackup && @rackup.server.to_s.demodulize == 'Thin') end |
#to_hash ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/dumper/stack.rb', line 40 def to_hash { framework: @framework, rails_env: @rails_env, rails_version: @rails_version, dispatcher: @dispatcher, configs: Hash[@configs.map{|k, config| [ k, config.reject{|k,v| k == :password } ] }] } end |
#unicorn? ⇒ Boolean
Dispatcher
56 57 58 |
# File 'lib/dumper/stack.rb', line 56 def unicorn? defined?(::Unicorn::HttpServer) && find_instance_in_object_space(::Unicorn::HttpServer) end |
#webrick? ⇒ Boolean
74 75 76 77 |
# File 'lib/dumper/stack.rb', line 74 def webrick? # defined?(::WEBrick::VERSION) @rackup and @rackup.server.to_s.demodulize == 'WEBrick' end |