Class: EasyJSONMatcher::SchemaLibrary
- Inherits:
-
Object
- Object
- EasyJSONMatcher::SchemaLibrary
- Defined in:
- lib/easy_json_matcher/schema_library.rb
Class Method Summary collapse
- .add_schema(name:, schema:) ⇒ Object
- .available_schemas ⇒ Object
-
.get_schema(name:, opts: {}) ⇒ Object
TODO: error message should read “called #name, not with #name”.
- .schema_for(name) ⇒ Object
-
.use_schema(name:, wrap_with: Validator) ⇒ Object
TODO: this method should use get_schema to ensure schema presence is checked.
Class Method Details
.add_schema(name:, schema:) ⇒ Object
18 19 20 |
# File 'lib/easy_json_matcher/schema_library.rb', line 18 def add_schema(name:, schema:) SCHEMAS[name] = schema end |
.available_schemas ⇒ Object
10 11 12 |
# File 'lib/easy_json_matcher/schema_library.rb', line 10 def available_schemas SCHEMAS.keys end |
.get_schema(name:, opts: {}) ⇒ Object
TODO: error message should read “called #name, not with #name”
23 24 25 26 27 28 29 30 31 |
# File 'lib/easy_json_matcher/schema_library.rb', line 23 def get_schema(name:, opts: {}) if schema = SCHEMAS[name] schema else lambda do |value| SCHEMAS[name]&.call(value: value) or raise MissingSchemaException.new(schema_name: name) end end end |
.schema_for(name) ⇒ Object
14 15 16 |
# File 'lib/easy_json_matcher/schema_library.rb', line 14 def schema_for(name) SCHEMAS[name] end |
.use_schema(name:, wrap_with: Validator) ⇒ Object
TODO: this method should use get_schema to ensure schema presence is checked
35 36 37 |
# File 'lib/easy_json_matcher/schema_library.rb', line 35 def use_schema(name:, wrap_with: Validator) wrap_with.new validate_with: get_schema(name: name) end |