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
82 83 84 85 86 87 88 89 |
# File 'lib/zeta/instance.rb', line 82 def cache_dir @lock.synchronize do return @cache_dir if @cache_dir full_path = File.(config[:contracts_cache_path]) FileUtils.mkdir_p(full_path) @cache_dir = full_path end end |
#clear_cache ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/zeta/instance.rb', line 91 def clear_cache @lock.synchronize do # 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 end |
#config_file ⇒ Object
66 67 68 69 |
# File 'lib/zeta/instance.rb', line 66 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
137 138 139 |
# File 'lib/zeta/instance.rb', line 137 def consume_object(type, data) current_service.consume_object(type, data) end |
#contracts_fulfilled?(reporter = nil) ⇒ Boolean
53 54 55 56 |
# File 'lib/zeta/instance.rb', line 53 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 |
# File 'lib/zeta/instance.rb', line 30 def convert_all! @lock.synchronize do infrastructure.convert_all! end end |
#current_service ⇒ Object
141 142 143 |
# File 'lib/zeta/instance.rb', line 141 def current_service @current_service ||= infrastructure.services[config[:service_name]] end |
#env ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/zeta/instance.rb', line 71 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
49 50 51 |
# File 'lib/zeta/instance.rb', line 49 def errors infrastructure.errors end |
#infrastructure ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/zeta/instance.rb', line 58 def infrastructure @lock.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( = {}) @lock = Monitor.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 @lock.synchronize do i = infrastructure clear_cache puts "Updating #{cache_dir}" if verbose? update_other_contracts update_own_contracts i.convert_all! end true end |
#update_own_contracts ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zeta/instance.rb', line 36 def update_own_contracts @lock.synchronize do 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 end |
#validate_object_to_consume(type, data) ⇒ Object
133 134 135 |
# File 'lib/zeta/instance.rb', line 133 def validate_object_to_consume(type, data) current_service.validate_object_to_consume(type, data) end |
#validate_object_to_consume!(type, data) ⇒ Object
129 130 131 |
# File 'lib/zeta/instance.rb', line 129 def validate_object_to_consume!(type, data) current_service.validate_object_to_consume!(type, data) end |
#validate_object_to_publish(type, data) ⇒ Object
125 126 127 |
# File 'lib/zeta/instance.rb', line 125 def validate_object_to_publish(type, data) current_service.validate_object_to_publish(type, data) end |
#validate_object_to_publish!(type, data) ⇒ Object
121 122 123 |
# File 'lib/zeta/instance.rb', line 121 def validate_object_to_publish!(type, data) current_service.validate_object_to_publish!(type, data) end |
#verbose=(val) ⇒ Object
145 146 147 |
# File 'lib/zeta/instance.rb', line 145 def verbose=(val) @options[:verbose] = !!val end |