Class: KrakendOpenAPI::KrakendWriter
- Inherits:
-
Object
- Object
- KrakendOpenAPI::KrakendWriter
- Defined in:
- lib/writers/krakend_writer.rb
Overview
Writes KrakenD configuration to a file
Instance Method Summary collapse
- #file_path ⇒ Object
-
#initialize(endpoints, importer_config) ⇒ KrakendWriter
constructor
A new instance of KrakendWriter.
- #write ⇒ Object
Constructor Details
#initialize(endpoints, importer_config) ⇒ KrakendWriter
Returns a new instance of KrakendWriter.
8 9 10 11 12 |
# File 'lib/writers/krakend_writer.rb', line 8 def initialize(endpoints, importer_config) @endpoints = endpoints @importer_config = importer_config @output_file_path = @importer_config['output'] || 'output.json' end |
Instance Method Details
#file_path ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/writers/krakend_writer.rb', line 24 def file_path pwd = File.(Dir.pwd) if Pathname.new(@output_file_path).absolute? @output_file_path else File.(@output_file_path, pwd) end end |
#write ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/writers/krakend_writer.rb', line 14 def write pretty_output = !!@importer_config['pretty'] # rubocop:disable Style/DoubleNegation json_generate = pretty_output ? ->(obj) { JSON.pretty_generate(obj) } : ->(obj) { JSON.dump(obj) } File.write(file_path, json_generate.call({ '$schema': 'https://www.krakend.io/schema/v3.json', version: 3, endpoints: @endpoints })) end |