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



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

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



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

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

#consume_object(type, data) ⇒ Object



111
112
113
# File 'lib/zeta/instance.rb', line 111

def consume_object(type, data)
  current_service.consume_object(type, data)
end

#contracts_fulfilled?Boolean

Returns:

  • (Boolean)


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

def contracts_fulfilled?
  reporter = Lacerda::Reporters::Stdout.new(verbose: verbose?)
  infrastructure.contracts_fulfilled?(reporter)
end

#current_serviceObject



115
116
117
# File 'lib/zeta/instance.rb', line 115

def current_service
  @current_service ||= infrastructure.services[config[:service_name]]
end

#envObject



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

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



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

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

#validate_object_to_consume(type, data) ⇒ Object



107
108
109
# File 'lib/zeta/instance.rb', line 107

def validate_object_to_consume(type, data)
  current_service.validate_object_to_consume(type, data)
end

#validate_object_to_consume!(type, data) ⇒ Object



103
104
105
# File 'lib/zeta/instance.rb', line 103

def validate_object_to_consume!(type, data)
  current_service.validate_object_to_consume!(type, data)
end

#validate_object_to_publish(type, data) ⇒ Object



99
100
101
# File 'lib/zeta/instance.rb', line 99

def validate_object_to_publish(type, data)
  current_service.validate_object_to_publish(type, data)
end

#validate_object_to_publish!(type, data) ⇒ Object



95
96
97
# File 'lib/zeta/instance.rb', line 95

def validate_object_to_publish!(type, data)
  current_service.validate_object_to_publish!(type, data)
end