Class: Dumper::Stack

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Utility::ObjectFinder

#find_instance_in_object_space

Constructor Details

#initializeStack

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

#configsObject

Returns the value of attribute configs.



11
12
13
# File 'lib/dumper/stack.rb', line 11

def configs
  @configs
end

#dispatcherObject

Returns the value of attribute dispatcher.



11
12
13
# File 'lib/dumper/stack.rb', line 11

def dispatcher
  @dispatcher
end

#frameworkObject

Returns the value of attribute framework.



11
12
13
# File 'lib/dumper/stack.rb', line 11

def framework
  @framework
end

#rackupObject

Returns the value of attribute rackup.



11
12
13
# File 'lib/dumper/stack.rb', line 11

def rackup
  @rackup
end

#rails_envObject

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

Returns:

  • (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

Returns:

  • (Boolean)


60
61
62
# File 'lib/dumper/stack.rb', line 60

def passenger?
  defined?(::Passenger::AbstractServer) || defined?(::IN_PHUSION_PASSENGER)
end

#resque?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/dumper/stack.rb', line 79

def resque?
  defined?(::Resque) && (ENV['QUEUES'] || ENV['QUEUE'])
end

#supported?Boolean

Compatibility

Returns:

  • (Boolean)


51
52
53
# File 'lib/dumper/stack.rb', line 51

def supported?
  @is_supported_rails_version && @dispatcher && !@configs.empty?
end

#thin?Boolean

Returns:

  • (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_hashObject



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

Returns:

  • (Boolean)


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

Returns:

  • (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