Module: EasyTalk::Schema::ClassMethods
- Includes:
- EasyTalk::SchemaMethods
- Defined in:
- lib/easy_talk/schema.rb
Overview
Class methods for schema-only models.
Instance Method Summary collapse
-
#additional_properties_allowed? ⇒ Boolean
Check if additional properties are allowed.
-
#define_schema { ... } ⇒ Object
Define the schema for the model using the provided block.
-
#json_schema ⇒ Hash
included
from EasyTalk::SchemaMethods
Returns the JSON schema for the model.
-
#properties ⇒ Array<Symbol>
Returns the property names defined in the schema.
-
#ref_template ⇒ String
included
from EasyTalk::SchemaMethods
Returns the reference template for the model.
-
#schema ⇒ Hash
Returns the schema for the model.
-
#schema_definition ⇒ SchemaDefinition
Returns the schema definition for the model.
Instance Method Details
#additional_properties_allowed? ⇒ Boolean
Check if additional properties are allowed.
176 177 178 |
# File 'lib/easy_talk/schema.rb', line 176 def additional_properties_allowed? @schema_definition&.schema&.fetch(:additional_properties, false) end |
#define_schema { ... } ⇒ Object
Define the schema for the model using the provided block. Unlike EasyTalk::Model, this does NOT apply any validations.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/easy_talk/schema.rb', line 150 def define_schema(&) raise ArgumentError, 'The class must have a name' unless name.present? @schema_definition = SchemaDefinition.new(name) @schema_definition.klass = self @schema_definition.instance_eval(&) # Define accessors for all properties defined_properties = (@schema_definition.schema[:properties] || {}).keys attr_accessor(*defined_properties) # NO validations are applied - this is schema-only @schema_definition end |
#json_schema ⇒ Hash Originally defined in module EasyTalk::SchemaMethods
Returns the JSON schema for the model. This is the final output that includes the $schema keyword if configured.
#properties ⇒ Array<Symbol>
Returns the property names defined in the schema.
183 184 185 |
# File 'lib/easy_talk/schema.rb', line 183 def properties (@schema_definition&.schema&.dig(:properties) || {}).keys end |
#ref_template ⇒ String Originally defined in module EasyTalk::SchemaMethods
Returns the reference template for the model.
#schema ⇒ Hash
Returns the schema for the model.
137 138 139 140 141 142 143 |
# File 'lib/easy_talk/schema.rb', line 137 def schema @schema ||= if defined?(@schema_definition) && @schema_definition build_schema(@schema_definition) else {} end end |
#schema_definition ⇒ SchemaDefinition
Returns the schema definition for the model.
169 170 171 |
# File 'lib/easy_talk/schema.rb', line 169 def schema_definition @schema_definition ||= {} end |