Class: Prmd::Combiner
- Inherits:
-
Object
- Object
- Prmd::Combiner
- Defined in:
- lib/prmd/core/combiner.rb
Overview
Schema combiner
Instance Method Summary collapse
- #combine(*schemata) ⇒ Prmd::Schema
-
#initialize(properties = {}) ⇒ Combiner
constructor
A new instance of Combiner.
Constructor Details
#initialize(properties = {}) ⇒ Combiner
Returns a new instance of Combiner.
10 11 12 13 14 15 |
# File 'lib/prmd/core/combiner.rb', line 10 def initialize(properties = {}) @properties = properties @schema = properties.fetch(:schema) @base = properties.fetch(:base, {}) @meta = properties.fetch(:meta, {}) end |
Instance Method Details
#combine(*schemata) ⇒ Prmd::Schema
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/prmd/core/combiner.rb', line 55 def combine(*schemata) # tracks which entities where defined in which file schemata_map = {} data = {} data.merge!(@base) data.merge!(@meta) schemata.each do |schema| id = schema.fetch('id') id_ary = id.split('/').last if s = schemata_map[id] $stderr.puts "`#{id}` (from #{schema.filename}) was already defined" \ "in `#{s.filename}` and will overwrite the first" \ "definition" end # avoinding damaging the original schema = schema.dup # schemas are now in a single scope by combine .delete('id') schemata_map[id] = data['definitions'][id_ary] = .to_h data['properties'][id_ary] = { '$ref' => "#/definitions/#{id_ary}" } reference_localizer(data['definitions'][id_ary]) end Prmd::Schema.new(data) end |