Class: Esquema::SchemaEnhancer
- Inherits:
-
Object
- Object
- Esquema::SchemaEnhancer
- Defined in:
- lib/esquema/schema_enhancer.rb
Overview
The SchemaEnhancer class is responsible for enhancing the schema of a model.
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(model, schema_enhancements) ⇒ SchemaEnhancer
constructor
A new instance of SchemaEnhancer.
-
#model_description(description) ⇒ Object
Sets the description for the model.
-
#model_title(title) ⇒ Object
Sets the title for the model.
-
#property(name, options = {}) ⇒ Object
Adds a property to the schema.
-
#virtual_property(name, options = {}) ⇒ Object
Adds a virtual property to the schema.
Constructor Details
#initialize(model, schema_enhancements) ⇒ SchemaEnhancer
Returns a new instance of SchemaEnhancer.
12 13 14 15 |
# File 'lib/esquema/schema_enhancer.rb', line 12 def initialize(model, schema_enhancements) @schema_enhancements = schema_enhancements @model = model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
10 11 12 |
# File 'lib/esquema/schema_enhancer.rb', line 10 def model @model end |
Instance Method Details
#model_description(description) ⇒ Object
Sets the description for the model.
20 21 22 |
# File 'lib/esquema/schema_enhancer.rb', line 20 def model_description(description) @schema_enhancements[:model_description] = description end |
#model_title(title) ⇒ Object
Sets the title for the model.
27 28 29 |
# File 'lib/esquema/schema_enhancer.rb', line 27 def model_title(title) @schema_enhancements[:model_title] = title end |
#property(name, options = {}) ⇒ Object
Adds a property to the schema.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/esquema/schema_enhancer.rb', line 35 def property(name, = {}) validate_property_as_attribute_for(name, ) type = resolve_type(name, ) KeywordValidator.validate!(name, type, ) @schema_enhancements[:properties] ||= {} @schema_enhancements[:properties][name] = end |
#virtual_property(name, options = {}) ⇒ Object
Adds a virtual property to the schema.
50 51 52 53 |
# File 'lib/esquema/schema_enhancer.rb', line 50 def virtual_property(name, = {}) [:virtual] = true property(name, ) end |