lib/jimmy/domain.rb in jimmy-0.4.4 vs lib/jimmy/domain.rb in jimmy-0.4.5
- old
+ new
@@ -56,16 +56,16 @@
def [](schema_name)
@schemas[schema_name.to_s]
end
- def export(path = nil)
+ def export(path = nil, &serializer)
path = Pathname(path) if path.is_a? String
raise 'Please specify an export directory' unless path.is_a?(Pathname) && (path.directory? || !path.exist?)
path.mkpath
- @schemas.each { |name, schema| export_schema schema, path + "#{name.to_s}.json" }
- @types.each { |name, schema| export_schema schema, path + 'types' + "#{name.to_s}.json" }
+ @schemas.each { |name, schema| export_schema schema, path + "#{name.to_s}.json", &serializer }
+ @types.each { |name, schema| export_schema schema, path + 'types' + "#{name.to_s}.json", &serializer }
end
def uri_for(name)
@uri_formatter.call root, name
end
@@ -96,10 +96,10 @@
end
end
def export_schema(schema, target_path)
target_path.parent.mkpath
- target_path.write JSON.pretty_generate(schema.to_h)
+ target_path.write block_given? ? yield(schema.to_h) : JSON.pretty_generate(schema.to_h)
end
SchemaCreation.apply_to self
end