Module: Zeta::Instance

Included in:
Zeta
Defined in:
lib/zeta/instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



11
12
13
# File 'lib/zeta/instance.rb', line 11

def config
  @config
end

Instance Method Details

#cache_dirObject



72
73
74
75
76
77
# File 'lib/zeta/instance.rb', line 72

def cache_dir
    return @cache_dir if @cache_dir
    full_path = File.expand_path(config[:contracts_cache_path])
    FileUtils.mkdir_p(full_path)
    @cache_dir = full_path
end

#config_fileObject



56
57
58
59
# File 'lib/zeta/instance.rb', line 56

def config_file
  return File.expand_path(@options[:config_file]) if @options[:config_file]
  File.join(Dir.pwd, 'config', 'zeta.yml')
end

#contracts_fulfilled?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/zeta/instance.rb', line 44

def contracts_fulfilled?
  infrastructure.contracts_fulfilled?
end

#envObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/zeta/instance.rb', line 61

def env
  return @options[:env].to_sym if @options[:env]
  if Object.const_defined?('Rails')
    Rails.env.to_sym
  else
    guessed = ENV['RAILS_ENV'] || ENV['RACK_ENV']
    raise "No environment given" unless guessed
    guessed
  end
end

#errorsObject



40
41
42
# File 'lib/zeta/instance.rb', line 40

def errors
  infrastructure.errors
end

#infrastructureObject



48
49
50
51
52
53
54
# File 'lib/zeta/instance.rb', line 48

def infrastructure
  @mutex.synchronize do
    return @infrastructure if @infrastructure
    @infrastructure = Lacerda::Infrastructure.new(data_dir: cache_dir, verbose: verbose?)
    @infrastructure
  end
end

#initialize(options = {}) ⇒ Object



13
14
15
16
17
# File 'lib/zeta/instance.rb', line 13

def initialize(options = {})
  @mutex = Mutex.new
  @options = options
  puts "Using config file #{config_file}" if verbose?
end

#update_contractsObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/zeta/instance.rb', line 19

def update_contracts
  i = infrastructure
  @mutex.synchronize do
    puts "Updating #{cache_dir}" if verbose?
    update_other_contracts
    update_own_contracts
    i.convert_all!
  end
  true
end

#update_own_contractsObject



30
31
32
33
34
35
36
37
38
# File 'lib/zeta/instance.rb', line 30

def update_own_contracts
  contract_files.each do |file|
    source_file = File.join(config[:contracts_path], file)
    target_file = File.join(cache_dir, config[:service_name], file)
    puts "cp #{source_file} #{target_file}" if verbose?
    FileUtils.rm_f(target_file)
    FileUtils.cp(source_file, target_file) if File.exists?(source_file)
  end
end