Class: Meta::JsonSchema::ScopingSchema

Inherits:
BaseSchema
  • Object
show all
Defined in:
lib/meta/json_schema/schemas/scoping_schema.rb

Instance Attribute Summary collapse

Attributes inherited from BaseSchema

#options

Instance Method Summary collapse

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

#schemaObject (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_matcherObject (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