Class: Meta::JsonSchema::StagingSchema
- Inherits:
-
BaseSchema
- Object
- BaseSchema
- Meta::JsonSchema::StagingSchema
- Defined in:
- lib/meta/json_schema/schemas/staging_schema.rb
Overview
内含 param_schema, render_schema, default_schema,分别用于不同的阶段。
Instance Attribute Summary collapse
-
#param_schema ⇒ Object
readonly
Returns the value of attribute param_schema.
-
#render_schema ⇒ Object
readonly
Returns the value of attribute render_schema.
Attributes inherited from BaseSchema
Class Method Summary collapse
Instance Method Summary collapse
- #defined_scopes(stage:, **kwargs) ⇒ Object
- #filter(value, user_options = {}) ⇒ Object
-
#initialize(param_schema:, render_schema:) ⇒ StagingSchema
constructor
A new instance of StagingSchema.
- #staged(stage) ⇒ Object
- #to_schema_doc(stage:, **kwargs) ⇒ Object
Methods inherited from BaseSchema
#filter?, #find_schema, #if?, #scoped, #to_schema, #value?
Constructor Details
#initialize(param_schema:, render_schema:) ⇒ StagingSchema
Returns a new instance of StagingSchema.
13 14 15 16 17 18 19 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 13 def initialize(param_schema:, render_schema:) raise ArgumentError, 'param_schema 选项重复提交为 StagingSchema' if param_schema.is_a?(StagingSchema) raise ArgumentError, 'render_schema 选项重复提交为 StagingSchema' if render_schema.is_a?(StagingSchema) @param_schema = param_schema @render_schema = render_schema end |
Instance Attribute Details
#param_schema ⇒ Object (readonly)
Returns the value of attribute param_schema.
11 12 13 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 11 def param_schema @param_schema end |
#render_schema ⇒ Object (readonly)
Returns the value of attribute render_schema.
11 12 13 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 11 def render_schema @render_schema end |
Class Method Details
.build_from_options(options, build_schema = ->(opts) { BaseSchema.new(opts) }) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 49 def self.(, build_schema = ->(opts) { BaseSchema.new(opts) }) param_opts, render_opts, common_opts = SchemaOptions.divide_to_param_and_render() if param_opts == common_opts && render_opts == common_opts return ScopingSchema.(common_opts, build_schema) else StagingSchema.new( param_schema: param_opts ? ScopingSchema.(param_opts, build_schema) : UnsupportedSchema.new(:stage, :param), render_schema: render_opts ? ScopingSchema.(render_opts, build_schema) : UnsupportedSchema.new(:stage, :render) ) end end |
Instance Method Details
#defined_scopes(stage:, **kwargs) ⇒ Object
41 42 43 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 41 def defined_scopes(stage:, **kwargs) staged(stage).defined_scopes(stage: stage, **kwargs) end |
#filter(value, user_options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 21 def filter(value, = {}) if [:stage] == :param param_schema.filter(value, ) elsif [:stage] == :render render_schema.filter(value, ) else raise ArgumentError, "stage 选项必须是 :param 或 :render" end end |
#staged(stage) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 31 def staged(stage) if stage == :param param_schema elsif stage == :render render_schema else raise ArgumentError, "stage 选项必须是 :param 或 :render" end end |
#to_schema_doc(stage:, **kwargs) ⇒ Object
45 46 47 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 45 def to_schema_doc(stage:, **kwargs) staged(stage).to_schema_doc(stage: stage, **kwargs) end |