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,分别用于不同的阶段。
Constant Summary
Constants inherited from BaseSchema
BaseSchema::OPTIONS_CHECKER, BaseSchema::USER_OPTIONS_CHECKER
Instance Attribute Summary collapse
-
#default_schema ⇒ Object
readonly
Returns the value of attribute default_schema.
-
#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
- #filter(value, user_options = {}) ⇒ Object
-
#initialize(param_schema:, render_schema:, default_schema:) ⇒ StagingSchema
constructor
A new instance of StagingSchema.
- #staged(stage) ⇒ Object
Methods inherited from BaseSchema
#filter?, #find_schema, #if?, #scoped, #to_schema, #to_schema_doc, #value?
Constructor Details
#initialize(param_schema:, render_schema:, default_schema:) ⇒ StagingSchema
Returns a new instance of StagingSchema.
14 15 16 17 18 19 20 21 22 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 14 def initialize(param_schema:, render_schema:, default_schema:) raise ArgumentError, 'param_schema 选项重复提交为 StagingSchema' if param_schema.is_a?(StagingSchema) raise ArgumentError, 'render_schema 选项重复提交为 StagingSchema' if render_schema.is_a?(StagingSchema) raise ArgumentError, 'default_schema 选项重复提交为 StagingSchema' if default_schema.is_a?(StagingSchema) @param_schema = param_schema @render_schema = render_schema @default_schema = default_schema end |
Instance Attribute Details
#default_schema ⇒ Object (readonly)
Returns the value of attribute default_schema.
12 13 14 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 12 def default_schema @default_schema end |
#param_schema ⇒ Object (readonly)
Returns the value of attribute param_schema.
12 13 14 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 12 def param_schema @param_schema end |
#render_schema ⇒ Object (readonly)
Returns the value of attribute render_schema.
12 13 14 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 12 def render_schema @render_schema end |
Class Method Details
.build_from_options(options, build_schema = ->(opts) { BaseSchema.new(opts) }) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 44 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), default_schema: ScopingSchema.(common_opts, build_schema), ) end end |
Instance Method Details
#filter(value, user_options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 24 def filter(value, = {}) if [:stage] == :param param_schema.filter(value, ) elsif [:stage] == :render render_schema.filter(value, ) else default_schema.filter(value, ) end end |
#staged(stage) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/meta/json_schema/schemas/staging_schema.rb', line 34 def staged(stage) if stage == :param param_schema elsif stage == :render render_schema else default_schema end end |