Class: Esquema::SchemaEnhancer

Inherits:
Object
  • Object
show all
Defined in:
lib/esquema/schema_enhancer.rb

Overview

The SchemaEnhancer class is responsible for enhancing the schema of a model.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#modelObject (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.

Parameters:

  • description (String)

    The description of 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.

Parameters:

  • title (String)

    The title of 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.

Parameters:

  • name (Symbol)

    The name of the property.

  • options (Hash) (defaults to: {})

    Additional options for the property.



35
36
37
38
39
40
41
42
43
44
# File 'lib/esquema/schema_enhancer.rb', line 35

def property(name, options = {})
  validate_property_as_attribute_for(name, options)

  type = resolve_type(name, options)

  KeywordValidator.validate!(name, type, options)

  @schema_enhancements[:properties] ||= {}
  @schema_enhancements[:properties][name] = options
end

#virtual_property(name, options = {}) ⇒ Object

Adds a virtual property to the schema.

Parameters:

  • name (Symbol)

    The name of the virtual property.

  • options (Hash) (defaults to: {})

    Additional options for the virtual property.



50
51
52
53
# File 'lib/esquema/schema_enhancer.rb', line 50

def virtual_property(name, options = {})
  options[:virtual] = true
  property(name, options)
end