Class: Mina::Configuration

Inherits:
Object
  • Object
show all
Includes:
Helpers::Internal, Singleton
Defined in:
lib/mina/configuration.rb

Defined Under Namespace

Modules: DSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers::Internal

#deploy_script, #echo_cmd, #erb, #error!, #indent, #next_version, #report_time, #unindent

Methods included from Helpers::Output

#color, #print_command, #print_error, #print_info, #print_line, #print_status, #print_stderr, #print_stdout

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration


18
19
20
# File 'lib/mina/configuration.rb', line 18

def initialize
  @variables ||= {}
end

Instance Attribute Details

#variablesObject (readonly)

Returns the value of attribute variables


16
17
18
# File 'lib/mina/configuration.rb', line 16

def variables
  @variables
end

Instance Method Details

#ensure!(key) ⇒ Object


39
40
41
# File 'lib/mina/configuration.rb', line 39

def ensure!(key)
  error! "#{key} must be defined!" unless set?(key)
end

#fetch(key, default = nil) ⇒ Object


26
27
28
29
# File 'lib/mina/configuration.rb', line 26

def fetch(key, default = nil)
  value = ENV[key.to_s] || variables.fetch(key, default)
  value.respond_to?(:call) ? value.call : value
end

#remove(key) ⇒ Object


31
32
33
# File 'lib/mina/configuration.rb', line 31

def remove(key)
  variables.delete(key)
end

#reset!Object


43
44
45
# File 'lib/mina/configuration.rb', line 43

def reset!
  @variables = {}
end

#set(key, value = nil, &block) ⇒ Object


22
23
24
# File 'lib/mina/configuration.rb', line 22

def set(key, value = nil, &block)
  variables[key] = block || value
end

#set?(key) ⇒ Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/mina/configuration.rb', line 35

def set?(key)
  ENV.has_key?(key.to_s) || !variables.fetch(key, nil).nil?
end