Class: EY::Serverside::DependencyManager

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/engineyard-serverside/dependency_manager.rb,
lib/engineyard-serverside/dependency_manager/npm.rb,
lib/engineyard-serverside/dependency_manager/base.rb,
lib/engineyard-serverside/dependency_manager/bundler.rb,
lib/engineyard-serverside/dependency_manager/composer.rb,
lib/engineyard-serverside/dependency_manager/legacy_helpers.rb

Overview

DependencyManager encapsulates any number of dependency manager objects.

If a dependency manager indicates that it has detected the required file or state in order to run, it will be included in this set.

Methods called on an instance of DependencyManager are forwarded to any or all of the detected dependency managers.

Some actions, like check and install, are forwarded to all of the dependency managers. Other methods will take the first dependency manager that returns a value.

Defined Under Namespace

Modules: LegacyHelpers Classes: Base, Bundler, Composer, Npm

Constant Summary collapse

AVAILABLE_MANAGERS =

Registry pattern be damned. Hard code it and fix it when we want to support dynamic loading. Right now we have no way to load dependency managers dynamically, so why support it?

{
  'bundler'  => Bundler,
  'composer' => Composer,
  'npm'      => Npm
}

Instance Method Summary collapse

Constructor Details

#initialize(servers, config, shell, runner) ⇒ DependencyManager

Initialize detected dependency managers


32
33
34
35
# File 'lib/engineyard-serverside/dependency_manager.rb', line 32

def initialize(servers, config, shell, runner)
  @config = config
  @detected = select_managers(servers, config, shell, runner)
end

Instance Method Details

#checkObject

Verify application state with respect to dependency management. Warn if there is anything wrong with the dependency manager.


66
67
68
# File 'lib/engineyard-serverside/dependency_manager.rb', line 66

def check
  each { |m| m.check }
end

#detected?Boolean

Did we find any dependency managers?

Returns:

  • (Boolean)

60
61
62
# File 'lib/engineyard-serverside/dependency_manager.rb', line 60

def detected?
  any?
end

#each(&block) ⇒ Object


51
52
53
# File 'lib/engineyard-serverside/dependency_manager.rb', line 51

def each(&block)
  @detected.each(&block)
end

#installObject

Install dependencies for each of the dependency managers.


71
72
73
# File 'lib/engineyard-serverside/dependency_manager.rb', line 71

def install
  each { |m| m.install }
end

#rails_versionObject

Use the response from the first dependency manager that returns a rails version.


89
90
91
92
93
# File 'lib/engineyard-serverside/dependency_manager.rb', line 89

def rails_version
  version = nil
  find { |m| version = m.respond_to?(:rails_version) && m.rails_version }
  version
end

#select_managers(servers, config, shell, runner) ⇒ Object


37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/engineyard-serverside/dependency_manager.rb', line 37

def select_managers(servers, config, shell, runner)
  managers = AVAILABLE_MANAGERS.map do |name, klass|
    enabled = config[name]
    case enabled
    when 'false', false then nil
    when 'true',  true  then klass.new(servers, config, shell, runner)
    when 'detect', nil  then klass.detect(servers, config, shell, runner)
    else
      raise "Unknown value #{enabled.inspect} for option #{name.inspect}. Expected [true, false, detect]"
    end
  end
  managers.compact
end

#show_ey_config_instructionsObject

If services are installed, print intructions for using ey_config if the dependency manager has a compatible version.


97
98
99
# File 'lib/engineyard-serverside/dependency_manager.rb', line 97

def show_ey_config_instructions
  each { |m| m.respond_to?(:show_ey_config_instructions) && m.show_ey_config_instructions }
end

#to_aObject


55
56
57
# File 'lib/engineyard-serverside/dependency_manager.rb', line 55

def to_a
  @detected
end

#uses_sqlite3?Boolean

Assume application is not using sqlite3 unless a dependency manager says that sqlite is loaded and likely to be the only manager.

This may have problems in the future if one manager detects sqlite but another has the primary database manager.

Hopefully this method can be removed in the future and sqlite loading can be done without interfering with other systems.

Returns:

  • (Boolean)

83
84
85
# File 'lib/engineyard-serverside/dependency_manager.rb', line 83

def uses_sqlite3?
  any? { |m| m.respond_to?(:uses_sqlite3?) && m.uses_sqlite3? }
end