module Iuliia::Schema
Public Class Methods
[](schema_name)
click to toggle source
Fetch schema by schema name @param schema_name [String] @return [Iuliia::Schema]
# File lib/iuliia/schema.rb, line 9 def [](schema_name) schemas[schema_name] end
Also aliased as: schema
available_schemas()
click to toggle source
Return list of available schemas @return [Array]
# File lib/iuliia/schema.rb, line 18 def available_schemas load_schemas.transform_values(&:description).to_a end
Private Class Methods
load_schema(name)
click to toggle source
# File lib/iuliia/schema.rb, line 28 def load_schema(name) filename = "lib/schemas/#{name}.json" raise Exceptions::NonExistentSchemaException unless File.exist?(filename) JSON.parse(File.read(filename), object_class: OpenStruct, symbolize_names: true) end
load_schemas()
click to toggle source
# File lib/iuliia/schema.rb, line 35 def load_schemas Dir['lib/schemas/*.json'].map do |file| schema = load_schema(File.basename(file, '.json')) [schema.name, schema] end.to_h end
schemas()
click to toggle source
# File lib/iuliia/schema.rb, line 24 def schemas @schemas ||= Hash.new { |h, k| h[k] = load_schema(k) } end