Module: Nidyx::Reader
Defined Under Namespace
Classes: EmptySchemaError
Instance Method Summary collapse
-
#empty_schema?(schema) ⇒ Boolean
True if the schema is empty.
-
#read(path) ⇒ Hash
Reads JSON from a file.
Instance Method Details
#empty_schema?(schema) ⇒ Boolean
Returns true if the schema is empty.
39 40 41 42 43 |
# File 'lib/nidyx/reader.rb', line 39 def empty_schema?(schema) props = schema[PROPERTIES_KEY] items = schema[ITEMS_KEY] (!props || props.empty?) && (!items || items.empty?) end |
#read(path) ⇒ Hash
Reads JSON from a file
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/nidyx/reader.rb', line 15 def read(path) schema = nil begin # TODO: validate this is legitimate JSON Schema schema = JSON.parse(IO.read(path)) raise EmptySchemaError if empty_schema?(schema) rescue JSON::JSONError => e puts "Encountered an error reading JSON from #{path}" puts e. exit 1 rescue EmptySchemaError puts "Schema read from #{path} is empty" exit 1 rescue StandardError => e puts e. exit 1 end schema end |