lib/dato/json_schema_relationships.rb in dato-0.8.0 vs lib/dato/json_schema_relationships.rb in dato-0.8.1
- old
+ new
@@ -1,52 +1,48 @@
+# frozen_string_literal: true
+
module Dato
class JsonSchemaRelationships
attr_reader :schema
def initialize(schema)
@schema = schema
end
def relationships
- if !schema || !schema.properties['data']
- return {}
- end
+ return {} if !schema || !schema.properties["data"]
- entity = if schema.properties['data'].type.first == 'array'
- schema.properties['data'].items
+ entity = if schema.properties["data"].type.first == "array"
+ schema.properties["data"].items
else
- schema.properties['data']
+ schema.properties["data"]
end
- if !entity || !entity.properties['relationships'] || !entity.properties['relationships']
- return {}
- end
+ return {} if !entity || !entity.properties["relationships"] || !entity.properties["relationships"]
- relationships = entity.properties['relationships'].properties
+ relationships = entity.properties["relationships"].properties
relationships.each_with_object({}) do |(relationship, schema), acc|
- is_collection = schema.properties['data'].type.first == 'array'
+ is_collection = schema.properties["data"].type.first == "array"
types = if is_collection
- [type(schema.properties['data'].items)]
- elsif schema.properties['data'].type.first == 'object'
- [type(schema.properties['data'])]
- else
- schema.properties['data'].any_of.map do |option|
- type(option)
- end.compact
- end
+ [type(schema.properties["data"].items)]
+ elsif schema.properties["data"].type.first == "object"
+ [type(schema.properties["data"])]
+ else
+ schema.properties["data"].any_of.map do |option|
+ type(option)
+ end.compact
+ end
acc[relationship.to_sym] = {
collection: is_collection,
- types: types
+ types: types,
}
end
end
def type(definition)
- if definition.properties['type']
- definition.properties['type'].pattern.source.gsub(/(^\^|\$$)/, '')
- end
+ definition.properties["type"].pattern.source.gsub(/(^\^|\$$)/, "") if definition.properties["type"]
end
end
end