lib/avro/builder/rake/avro_generate_task.rb in avro-builder-0.14.1 vs lib/avro/builder/rake/avro_generate_task.rb in avro-builder-0.15.0.rc0
- old
+ new
@@ -33,12 +33,20 @@
raise '"root" must be specified for Avro DSL files' unless root
Avro::Builder.add_load_path(*[root, load_paths].flatten)
Dir["#{root}/**/*.rb"].each do |dsl_file|
puts "Generating Avro schema from #{dsl_file}"
output_file = dsl_file.sub('/dsl/', '/schema/').sub(/\.rb$/, ".#{filetype}")
- schema = Avro::Builder.build(filename: dsl_file)
- FileUtils.mkdir_p(File.dirname(output_file))
- File.write(output_file, schema.end_with?("\n") ? schema : schema << "\n")
+ dsl = Avro::Builder.build_dsl(filename: dsl_file)
+ if dsl.abstract?
+ if File.exist?(output_file)
+ puts "... Removing #{output_file} for abstract type"
+ FileUtils.rm(output_file)
+ end
+ else
+ schema = dsl.to_json
+ FileUtils.mkdir_p(File.dirname(output_file))
+ File.write(output_file, schema.end_with?("\n") ? schema : schema << "\n")
+ end
end
end
end
end
end