Module: Ronin::App::Schemas
- Defined in:
- lib/ronin/app/schemas/params_schema.rb,
lib/ronin/app/schemas/payloads/build_schema.rb,
lib/ronin/app/schemas/payloads/encoders/encode_schema.rb
Overview
Contains class methods for building dynamic dry-schemas.
Defined Under Namespace
Modules: Payloads
Class Method Summary collapse
-
.ParamsSchema(params) ⇒ Object
Builds a
Dry::Schema::Params
schema using a class'es defined params.
Class Method Details
.ParamsSchema(params) ⇒ Object
Builds a Dry::Schema::Params
schema using a class'es defined params.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ronin/app/schemas/params_schema.rb', line 38 def self.ParamsSchema(params) dsl = Dry::Schema::DSL.new(processor_type: Dry::Schema::Params) params.each do |name,param| schema_type = case param.type when Ronin::Core::Params::Types::Enum Types::String.enum(*param.type.values) when Ronin::Core::Params::Types::Boolean :bool when Ronin::Core::Params::Types::Integer :integer when Ronin::Core::Params::Types::Float :float else :string end if (param.required? && !param.has_default?) dsl.required(name).filled(schema_type) else dsl.optional(name).maybe(schema_type) end end return dsl.call end |