Class: Meta::JsonSchema::ScopingSchema
- Inherits:
-
BaseSchema
- Object
- BaseSchema
- Meta::JsonSchema::ScopingSchema
- Defined in:
- lib/meta/json_schema/schemas/scoping_schema.rb
Constant Summary collapse
- STAGING_SCHEMA_OPTIONS =
Utils::KeywordArgs::Builder.build do permit_extras true # TODO: 如果我想把 on 改名为 require_scopes,关键字参数的机制是否支持? key :on, alias_names: [:scope], default: [], normalizer: ->(required_scopes) { required_scopes = [] if required_scopes.nil? required_scopes = [required_scopes] unless required_scopes.is_a?(Array) required_scopes } end
Constants inherited from BaseSchema
BaseSchema::OPTIONS_CHECKER, BaseSchema::USER_OPTIONS_CHECKER
Instance Attribute Summary collapse
-
#on ⇒ Object
readonly
Returns the value of attribute on.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Attributes inherited from BaseSchema
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(required_scope: [], 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(required_scope: [], schema:) ⇒ ScopingSchema
Returns a new instance of ScopingSchema.
8 9 10 11 12 13 14 |
# File 'lib/meta/json_schema/schemas/scoping_schema.rb', line 8 def initialize(required_scope: [], schema:) raise ArgumentError, 'required_scope 选项不可传递 nil' if required_scope.nil? required_scope = [required_scope] unless required_scope.is_a?(Array) @on = required_scope @schema = schema end |
Instance Attribute Details
#on ⇒ Object (readonly)
Returns the value of attribute on.
6 7 8 |
# File 'lib/meta/json_schema/schemas/scoping_schema.rb', line 6 def on @on end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
6 7 8 |
# File 'lib/meta/json_schema/schemas/scoping_schema.rb', line 6 def schema @schema end |
Class Method Details
.build_from_options(options, build_schema) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/meta/json_schema/schemas/scoping_schema.rb', line 32 def self.(, build_schema) = STAGING_SCHEMA_OPTIONS.check() required_scope = .delete(:on) || [] schema = build_schema.call() schema = ScopingSchema.new(required_scope: required_scope, schema: schema) unless required_scope.empty? schema end |
Instance Method Details
#scoped(user_scopes) ⇒ Object
16 17 18 19 20 |
# File 'lib/meta/json_schema/schemas/scoping_schema.rb', line 16 def scoped(user_scopes) return schema if (on - user_scopes).empty? # required_scopes 应被消耗殆尽 UnsupportedSchema.new(:on, user_scopes) end |