Class: Lacerda::Infrastructure
- Inherits:
-
Object
- Object
- Lacerda::Infrastructure
- Defined in:
- lib/lacerda/infrastructure.rb
Instance Attribute Summary collapse
-
#data_dir ⇒ Object
readonly
Returns the value of attribute data_dir.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #consumers ⇒ Object
- #contracts_fulfilled?(reporter = nil) ⇒ Boolean
- #convert_all!(keep_intermediary_files = false) ⇒ Object
-
#initialize(options) ⇒ Infrastructure
constructor
A new instance of Infrastructure.
- #json_files ⇒ Object
- #mson_files ⇒ Object
- #publishers ⇒ Object
- #reload ⇒ Object
- #services ⇒ Object
Constructor Details
#initialize(options) ⇒ Infrastructure
Returns a new instance of Infrastructure.
8 9 10 11 12 13 |
# File 'lib/lacerda/infrastructure.rb', line 8 def initialize() @verbose = !!.fetch(:verbose, false) @data_dir = .fetch(:data_dir) @mutex1 = Mutex.new @mutex2 = Mutex.new end |
Instance Attribute Details
#data_dir ⇒ Object (readonly)
Returns the value of attribute data_dir.
6 7 8 |
# File 'lib/lacerda/infrastructure.rb', line 6 def data_dir @data_dir end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
6 7 8 |
# File 'lib/lacerda/infrastructure.rb', line 6 def errors @errors end |
Instance Method Details
#consumers ⇒ Object
73 74 75 76 77 |
# File 'lib/lacerda/infrastructure.rb', line 73 def consumers services.values.select do |service| service.consumed_objects.length > 0 end end |
#contracts_fulfilled?(reporter = nil) ⇒ Boolean
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/lacerda/infrastructure.rb', line 19 def contracts_fulfilled?(reporter = nil) reporter = Lacerda.validate_reporter(reporter) @mutex1.synchronize do @errors = {} # Check for incompatibility in published objects reporter.try(:check_publishing) publishers.each do |publisher| reporter.try(:check_publisher, publisher) publisher.satisfies_consumers?(verbose: @verbose, reporter: reporter) next if publisher.errors.empty? @errors.merge! publisher.errors end # Check for missing publishers reporter.try(:check_consuming) missing_publishers = {} consumers.each do |consumer| reporter.try(:check_consumer, consumer) consumer.consumed_objects.each do |object| publisher_exists = !object.publisher.nil? is_published = publisher_exists && object.publisher.publishes?(object.name) reporter.try(:check_consumed_object, object.name, object.publisher_name.camelize, publisher_exists, is_published) if publisher_exists next else missing_publishers[object.publisher_name.camelize] ||= [] missing_publishers[object.publisher_name.camelize] << consumer.name.camelize end end end # Report missing publishers unless missing_publishers.empty? missing = [] missing_publishers.each do |publisher, consumers| missing << "#{publisher} (consumed by #{consumers.join(', ')})" end errors["Missing publishers"] = missing end reporter.try(:result, @errors) @errors.empty? end end |
#convert_all!(keep_intermediary_files = false) ⇒ Object
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/lacerda/infrastructure.rb', line 79 def convert_all!(keep_intermediary_files = false) json_files.each{ |file| FileUtils.rm_f(file) } mson_files.each do |file| Lacerda::Conversion.mson_to_json_schema!( filename: file, keep_intermediary_files: keep_intermediary_files, verbose: @verbose) end reload end |
#json_files ⇒ Object
94 95 96 |
# File 'lib/lacerda/infrastructure.rb', line 94 def json_files Dir.glob(File.join(@data_dir, "/**/*.schema.json")) end |
#mson_files ⇒ Object
90 91 92 |
# File 'lib/lacerda/infrastructure.rb', line 90 def mson_files Dir.glob(File.join(@data_dir, "/**/*.mson")) end |
#publishers ⇒ Object
67 68 69 70 71 |
# File 'lib/lacerda/infrastructure.rb', line 67 def publishers services.values.select do |service| service.published_objects.length > 0 end end |
#reload ⇒ Object
15 16 17 |
# File 'lib/lacerda/infrastructure.rb', line 15 def reload @services = nil end |
#services ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/lacerda/infrastructure.rb', line 98 def services @mutex2.synchronize do return @services if @services @services = {}.with_indifferent_access dirs = Dir.glob(File.join(@data_dir, "*/")) dirs.each do |dir| service = Lacerda::Service.new(self, dir) @services[service.name] = service end @services end end |