Module: WordpressDeploy::Environments

Defined in:
lib/wordpress_deploy/environments.rb

Class Method Summary collapse

Class Method Details

.<<(*environments) ⇒ Object

Add a new environment. If the environment name is already in use it is not added.

Return the number of configurations currently loaded.



20
21
22
23
24
25
26
27
# File 'lib/wordpress_deploy/environments.rb', line 20

def <<(*environments)
  environments.flatten!
  environments.each do |env|
    env_name = (env.respond_to? :name) ? env.name : nil
    envs << env unless name? env_name
  end
  envs.count
end

.find(name) ⇒ Object

Raises:

  • (Exception)


40
41
42
43
44
45
46
# File 'lib/wordpress_deploy/environments.rb', line 40

def find(name)
  name_to_find = name.to_sym
  index = envs.index { |env| env.name === name_to_find }
  raise Exception,
        "#{name} is not a valid environment" if index.nil?
  envs[index]
end

.loadObject

Load the environment files in the configuration directory.



9
10
11
12
13
# File 'lib/wordpress_deploy/environments.rb', line 9

def load
  files = Dir[File.join(WordpressDeploy::Config.config_dir, "**/*.rb")]
  files.each { |file| require file }
  nil
end

.method_missing(method, *args, &block) ⇒ Object

Respond with the named configuration if the method name is a a valid configuration that has been loaded.



58
59
60
61
62
63
64
# File 'lib/wordpress_deploy/environments.rb', line 58

def method_missing(method, *args, &block)
  if name?(method.to_sym)
    find(method.to_sym)
  else
    super
  end
end

.name?(name) ⇒ Boolean

Test if the name is a valid Configuration name.

Return true if it is; false otherwise.

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/wordpress_deploy/environments.rb', line 33

def name?(name)
  name_to_find = name.to_sym
  !envs.index { |env| env.name === name_to_find }.nil?
end

.namesObject Also known as: available_names

Return an array of the available configuration symbol names.



50
51
52
# File 'lib/wordpress_deploy/environments.rb', line 50

def names
  envs.map { |config| config.name }
end

.respond_to?(method) ⇒ Boolean

Respond to an configuration name as though it is a method.

Returns:

  • (Boolean)


68
69
70
71
# File 'lib/wordpress_deploy/environments.rb', line 68

def respond_to?(method)
  return true if name?(method.to_sym)
  super
end