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.
11 12 13 14 15 16 17 |
# File 'lib/prmd/core/combiner.rb', line 11 def initialize(properties = {}) @properties = properties @schema = properties.fetch(:schema) @base = properties.fetch(:base, {}) @meta = properties.fetch(:meta, {}) @options = properties.fetch(:options, {}) end |
Instance Method Details
#combine(*schemata) ⇒ Prmd::Schema
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 |
# File 'lib/prmd/core/combiner.rb', line 28 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, @options) end |