Module: Zeta::Instance
- Included in:
- Zeta
- Defined in:
- lib/zeta/instance.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #cache_dir ⇒ Object
- #clear_cache ⇒ Object
- #config_file ⇒ Object
- #consume_object(type, data) ⇒ Object
- #contracts_fulfilled?(reporter = nil) ⇒ Boolean
- #convert_all! ⇒ Object
- #current_service ⇒ Object
- #env ⇒ Object
- #errors ⇒ Object
- #infrastructure ⇒ Object
- #initialize(options = {}) ⇒ Object
- #update_contracts ⇒ Object
- #update_own_contracts ⇒ Object
- #validate_object_to_consume(type, data) ⇒ Object
- #validate_object_to_consume!(type, data) ⇒ Object
- #validate_object_to_publish(type, data) ⇒ Object
- #validate_object_to_publish!(type, data) ⇒ Object
- #verbose=(val) ⇒ Object
Instance Attribute Details
#config ⇒ Object (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_dir ⇒ Object
81 82 83 84 85 86 |
# File 'lib/zeta/instance.rb', line 81 def cache_dir return @cache_dir if @cache_dir full_path = File.(config[:contracts_cache_path]) FileUtils.mkdir_p(full_path) @cache_dir = full_path end |
#clear_cache ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/zeta/instance.rb', line 88 def clear_cache # I'm afraid of FileUtils.rm_rf so I'll just delete all relevant files # and then rmdir all empty directories. Dir[File.join(cache_dir, "**/*.mson")].each{|f| FileUtils.rm(f) } Dir[File.join(cache_dir, "**/*.json")].each{|f| FileUtils.rm(f) } Dir[File.join(cache_dir, '*')].each do |d| next unless File.directory?(d) FileUtils.rmdir(d) rescue nil end end |
#config_file ⇒ Object
65 66 67 68 |
# File 'lib/zeta/instance.rb', line 65 def config_file return File.(@options[:config_file]) if @options[:config_file] File.join(Dir.pwd, 'config', 'zeta.yml') end |
#consume_object(type, data) ⇒ Object
130 131 132 |
# File 'lib/zeta/instance.rb', line 130 def consume_object(type, data) current_service.consume_object(type, data) end |
#contracts_fulfilled?(reporter = nil) ⇒ Boolean
52 53 54 55 |
# File 'lib/zeta/instance.rb', line 52 def contracts_fulfilled?(reporter = nil) reporter ||= Lacerda::Reporters::Stdout.new(verbose: verbose?) infrastructure.contracts_fulfilled?(reporter) end |
#convert_all! ⇒ Object
30 31 32 33 34 35 |
# File 'lib/zeta/instance.rb', line 30 def convert_all! i = infrastructure @mutex.synchronize do i.convert_all! end end |
#current_service ⇒ Object
134 135 136 |
# File 'lib/zeta/instance.rb', line 134 def current_service @current_service ||= infrastructure.services[config[:service_name]] end |
#env ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/zeta/instance.rb', line 70 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 |
#errors ⇒ Object
48 49 50 |
# File 'lib/zeta/instance.rb', line 48 def errors infrastructure.errors end |
#infrastructure ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/zeta/instance.rb', line 57 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 |
# File 'lib/zeta/instance.rb', line 13 def initialize( = {}) @mutex = Mutex.new @options = end |
#update_contracts ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/zeta/instance.rb', line 18 def update_contracts i = infrastructure @mutex.synchronize do clear_cache puts "Updating #{cache_dir}" if verbose? update_other_contracts update_own_contracts i.convert_all! end true end |
#update_own_contracts ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/zeta/instance.rb', line 37 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) FileUtils.mkdir_p(File.join(cache_dir, config[:service_name])) 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
126 127 128 |
# File 'lib/zeta/instance.rb', line 126 def validate_object_to_consume(type, data) current_service.validate_object_to_consume(type, data) end |
#validate_object_to_consume!(type, data) ⇒ Object
122 123 124 |
# File 'lib/zeta/instance.rb', line 122 def validate_object_to_consume!(type, data) current_service.validate_object_to_consume!(type, data) end |
#validate_object_to_publish(type, data) ⇒ Object
118 119 120 |
# File 'lib/zeta/instance.rb', line 118 def validate_object_to_publish(type, data) current_service.validate_object_to_publish(type, data) end |
#validate_object_to_publish!(type, data) ⇒ Object
114 115 116 |
# File 'lib/zeta/instance.rb', line 114 def validate_object_to_publish!(type, data) current_service.validate_object_to_publish!(type, data) end |
#verbose=(val) ⇒ Object
138 139 140 |
# File 'lib/zeta/instance.rb', line 138 def verbose=(val) @options[:verbose] = !!val end |