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
- #pow? ⇒ Boolean
-
#puma? ⇒ Boolean
Dispatcher.
- #resque? ⇒ Boolean
-
#supported? ⇒ Boolean
Compatibility.
- #thin? ⇒ Boolean
- #to_hash ⇒ Object
- #unicorn? ⇒ Boolean
- #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 45 46 47 48 |
# 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]) if [key].is_a?(Hash) database. = [key][:custom_options] database.format = [key][:format] end @databases[key] = database end # Which dispatcher? [ :puma, :unicorn, :passenger, :thin, :mongrel, :webrick, :pow, :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
84 85 86 87 |
# File 'lib/dumper/stack.rb', line 84 def mongrel? # defined?(::Mongrel::HttpServer) @rackup and @rackup.server.to_s.demodulize == 'Mongrel' end |
#passenger? ⇒ Boolean
75 76 77 |
# File 'lib/dumper/stack.rb', line 75 def passenger? defined?(::PhusionPassenger) || defined?(::Passenger::AbstractServer) || defined?(::IN_PHUSION_PASSENGER) end |
#pow? ⇒ Boolean
94 95 96 97 |
# File 'lib/dumper/stack.rb', line 94 def pow? # https://github.com/josh/nack/blob/master/bin/nack_worker defined?(::Nack::Server) && find_instance_in_object_space(::Nack::Server) end |
#puma? ⇒ Boolean
Dispatcher
66 67 68 69 |
# File 'lib/dumper/stack.rb', line 66 def puma? defined?(::Puma::Runner) && find_instance_in_object_space(::Puma::Runner) || # puma 2.3.0 or later (@rackup && @rackup.server.to_s.demodulize == 'Puma') end |
#resque? ⇒ Boolean
99 100 101 |
# File 'lib/dumper/stack.rb', line 99 def resque? defined?(::Resque) && (ENV['QUEUES'] || ENV['QUEUE']) end |
#supported? ⇒ Boolean
Compatibility
61 62 63 |
# File 'lib/dumper/stack.rb', line 61 def supported? @is_supported_rails_version && !!@dispatcher && !@databases.empty? end |
#thin? ⇒ Boolean
79 80 81 82 |
# File 'lib/dumper/stack.rb', line 79 def thin? defined?(::Thin::Server) && find_instance_in_object_space(::Thin::Server) || (@rackup && @rackup.server.to_s.demodulize == 'Thin') end |
#to_hash ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/dumper/stack.rb', line 50 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
71 72 73 |
# File 'lib/dumper/stack.rb', line 71 def unicorn? defined?(::Unicorn::HttpServer) && find_instance_in_object_space(::Unicorn::HttpServer) end |
#webrick? ⇒ Boolean
89 90 91 92 |
# File 'lib/dumper/stack.rb', line 89 def webrick? # defined?(::WEBrick::VERSION) @rackup and @rackup.server.to_s.demodulize == 'WEBrick' end |