Class: Divergence::Configuration

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/divergence/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/divergence/config.rb', line 9

def initialize
  @git_path = nil
  @app_path = nil
  @cache_path = nil

  @cache_num = 5

  @forward_host = 'localhost'
  @forward_port = 80

  @callback_store = {}
  @helpers = Divergence::Helpers.new(self)
end

Instance Attribute Details

#app_pathObject

Returns the value of attribute app_path.



5
6
7
# File 'lib/divergence/config.rb', line 5

def app_path
  @app_path
end

#cache_numObject

Returns the value of attribute cache_num.



6
7
8
# File 'lib/divergence/config.rb', line 6

def cache_num
  @cache_num
end

#cache_pathObject

Returns the value of attribute cache_path.



5
6
7
# File 'lib/divergence/config.rb', line 5

def cache_path
  @cache_path
end

#forward_hostObject

Returns the value of attribute forward_host.



7
8
9
# File 'lib/divergence/config.rb', line 7

def forward_host
  @forward_host
end

#forward_portObject

Returns the value of attribute forward_port.



7
8
9
# File 'lib/divergence/config.rb', line 7

def forward_port
  @forward_port
end

#git_pathObject

Returns the value of attribute git_path.



5
6
7
# File 'lib/divergence/config.rb', line 5

def git_path
  @git_path
end

Instance Method Details

#callback(name, run_path = nil, args = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/divergence/config.rb', line 50

def callback(name, run_path=nil, args = {})
  return unless @callback_store.has_key?(name)

  if run_path.nil? or !File.exists?(run_path)
    run_path = Dir.pwd
  end

  Application.log.debug "Execute callback: #{name.to_s} in #{run_path}"

  Dir.chdir run_path do
    @callback_store[name].each do |cb|
      @helpers.execute cb, args
    end
  end
end

#callbacks(*names, &block) ⇒ Object

Lets a user define a callback for a specific event



40
41
42
43
44
45
46
47
48
# File 'lib/divergence/config.rb', line 40

def callbacks(*names, &block)
  names.each do |name|
    unless @callback_store.has_key?(name)
      @callback_store[name] = []
    end

    @callback_store[name].push block
  end
end

#each(&block) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/divergence/config.rb', line 66

def each(&block)
  instance_variables.each do |key|
    if block_given?
      block.call key, instance_variable_get(key)
    else
      yield instance_variable_get(key)
    end
  end
end

#ok?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/divergence/config.rb', line 23

def ok?
  [:git_path, :app_path, :cache_path].each do |path|
    if instance_variable_get("@#{path}").nil?
      raise "Configure #{path} before running"
    end
  end

  unless File.exists?(@git_path)
    raise "Configured git path not found: #{@git_path}"
  end

  unless File.exists?(@cache_path)
    FileUtils.mkdir_p @cache_path
  end
end