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
72 73 74 75 76 |
# File 'lib/lacerda/infrastructure.rb', line 72 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 |
# 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| if object.publisher reporter.try(:object_publisher_existing, object, true) next else reporter.try(:object_publisher_existing, object, false) 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
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/lacerda/infrastructure.rb', line 78 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
93 94 95 |
# File 'lib/lacerda/infrastructure.rb', line 93 def json_files Dir.glob(File.join(@data_dir, "/**/*.schema.json")) end |
#mson_files ⇒ Object
89 90 91 |
# File 'lib/lacerda/infrastructure.rb', line 89 def mson_files Dir.glob(File.join(@data_dir, "/**/*.mson")) end |
#publishers ⇒ Object
66 67 68 69 70 |
# File 'lib/lacerda/infrastructure.rb', line 66 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
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/lacerda/infrastructure.rb', line 97 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 |