Class: Meta::JsonSchema::ScopingSchema
- Inherits:
-
BaseSchema
- Object
- BaseSchema
- Meta::JsonSchema::ScopingSchema
- Defined in:
- lib/meta/json_schema/schemas/scoping_schema.rb
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#scope_matcher ⇒ Object
readonly
Returns the value of attribute scope_matcher.
Attributes inherited from BaseSchema
Instance Method Summary collapse
- #defined_scopes(**kwargs) ⇒ Object
-
#initialize(scope_matcher:, schema:) ⇒ ScopingSchema
constructor
A new instance of ScopingSchema.
- #scoped(user_scopes) ⇒ Object
Methods inherited from BaseSchema
#filter, #filter?, #find_schema, #if?, #staged, #to_schema, #to_schema_doc, #value?
Constructor Details
#initialize(scope_matcher:, schema:) ⇒ ScopingSchema
Returns a new instance of ScopingSchema.
11 12 13 14 15 16 |
# File 'lib/meta/json_schema/schemas/scoping_schema.rb', line 11 def initialize(scope_matcher:, schema:) # raise ArgumentError, 'scope_matcher 不能是一个数组' if scope_matcher.is_a?(Array) @scope_matcher = Scope::Utils.parse(scope_matcher) @schema = schema end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
9 10 11 |
# File 'lib/meta/json_schema/schemas/scoping_schema.rb', line 9 def schema @schema end |
#scope_matcher ⇒ Object (readonly)
Returns the value of attribute scope_matcher.
9 10 11 |
# File 'lib/meta/json_schema/schemas/scoping_schema.rb', line 9 def scope_matcher @scope_matcher end |
Instance Method Details
#defined_scopes(**kwargs) ⇒ Object
22 23 24 25 26 |
# File 'lib/meta/json_schema/schemas/scoping_schema.rb', line 22 def defined_scopes(**kwargs) current = scope_matcher.defined_scopes deep = schema.defined_scopes(**kwargs) (current + deep).uniq end |
#scoped(user_scopes) ⇒ Object
18 19 20 |
# File 'lib/meta/json_schema/schemas/scoping_schema.rb', line 18 def scoped(user_scopes) @scope_matcher.match?(user_scopes) ? schema : unsupported_schema(user_scopes) end |