lib/jimmy/domain.rb in jimmy-0.3.3 vs lib/jimmy/domain.rb in jimmy-0.3.4
- old
+ new
@@ -14,10 +14,11 @@
@root = URI(root)
@schemas = {}
@types = {}
@partials = {}
@import_paths = []
+ @uri_formatter = -> _, name { @root + "#{name}.json#" }
end
def domain
self
end
@@ -63,10 +64,18 @@
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" }
end
+ def uri_for(name)
+ @uri_formatter.call root, name
+ end
+
+ def uri_format(&block)
+ @uri_formatter = block
+ end
+
private
def glob(base_path, only: '.', ignore: nil, &block)
lookup_path = base_path + only
Dir[lookup_path + '**/*.rb'].each do |full_path|
@@ -78,9 +87,10 @@
yield *args
end
end
def load_schema_from_path(path, name)
+ @schema_name = name
instance_eval(path.read, path.to_s).schema.tap do |schema|
schema.name = name.to_s
JSON::Validator.add_schema JSON::Schema.new(schema.to_h, nil)
end
end