Class: Esquema::SchemaEnhancer
- Inherits:
-
Object
- Object
- Esquema::SchemaEnhancer
- Defined in:
- lib/esquema/schema_enhancer.rb
Constant Summary collapse
- VALID_OPTIONS =
i[title description maxLength minLength pattern maxItems minItems uniqueItems maxProperties minProperties properties additionalProperties dependencies enum format multipleOf maximum exclusiveMaximum minimum exclusiveMinimum const allOf anyOf oneOf not default].freeze
- TYPE_MAPPINGS =
{ date: Date, datetime: DateTime, time: Time, string: String, text: String, integer: Integer, float: Float, decimal: BigDecimal, boolean: [TrueClass, FalseClass], array: Array, object: Object }.freeze
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
- #model_title(title) ⇒ Object
- #property(name, options = {}) ⇒ Object
Constructor Details
#initialize(model, schema_enhancements) ⇒ SchemaEnhancer
Returns a new instance of SchemaEnhancer.
26 27 28 29 |
# File 'lib/esquema/schema_enhancer.rb', line 26 def initialize(model, schema_enhancements) @schema_enhancements = schema_enhancements @model = model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
24 25 26 |
# File 'lib/esquema/schema_enhancer.rb', line 24 def model @model end |
Instance Method Details
#model_description(description) ⇒ Object
31 32 33 |
# File 'lib/esquema/schema_enhancer.rb', line 31 def model_description(description) @schema_enhancements[:model_description] = description end |
#model_title(title) ⇒ Object
35 36 37 |
# File 'lib/esquema/schema_enhancer.rb', line 35 def model_title(title) @schema_enhancements[:model_title] = title end |
#property(name, options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/esquema/schema_enhancer.rb', line 39 def property(name, = {}) db_type = model.type_for_attribute(name).type klass_type = Array(TYPE_MAPPINGS[db_type]) validate_default_value([:default], klass_type, db_type) validate_enum_values([:enum], klass_type, db_type) .assert_valid_keys(VALID_OPTIONS) @schema_enhancements[:properties] ||= {} @schema_enhancements[:properties][name] = end |