Class: Explicit::Type::Enum
- Inherits:
-
Explicit::Type
- Object
- Explicit::Type
- Explicit::Type::Enum
- Defined in:
- lib/explicit/type/enum.rb
Instance Attribute Summary collapse
-
#allowed_values ⇒ Object
readonly
Returns the value of attribute allowed_values.
Attributes inherited from Explicit::Type
#auth_type, #default, #description, #nilable, #param_location
Instance Method Summary collapse
-
#initialize(allowed_values) ⇒ Enum
constructor
A new instance of Enum.
- #json_schema(flavour) ⇒ Object
- #validate(value) ⇒ Object
Methods inherited from Explicit::Type
#auth_basic?, #auth_bearer?, build, #error_i18n, #mcp_schema, #merge_base_json_schema, #param_location_body?, #param_location_path?, #param_location_query?, #required?, #swagger_i18n, #swagger_schema
Constructor Details
#initialize(allowed_values) ⇒ Enum
Returns a new instance of Enum.
6 7 8 |
# File 'lib/explicit/type/enum.rb', line 6 def initialize(allowed_values) @allowed_values = allowed_values end |
Instance Attribute Details
#allowed_values ⇒ Object (readonly)
Returns the value of attribute allowed_values.
4 5 6 |
# File 'lib/explicit/type/enum.rb', line 4 def allowed_values @allowed_values end |
Instance Method Details
#json_schema(flavour) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/explicit/type/enum.rb', line 32 def json_schema(flavour) { type: "string", enum: allowed_values } end |
#validate(value) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/explicit/type/enum.rb', line 10 def validate(value) if allowed_values.include?(value) [:ok, value] else error_i18n("enum", allowed_values: allowed_values.inspect) end end |