Class: Upgrow::Schema
- Inherits:
-
Object
- Object
- Upgrow::Schema
- Defined in:
- lib/upgrow/schema.rb
Overview
Defines attribute names to be set in a Model class. This allows pre-defining a set of attributes to be set at once in a Model without having to declare each one by hand.
A Schema is a loose concept. This is just a convenience class to be used when a more robust object is not present. In reality, any object that responds to ‘attribute_names` can be used as a Schema.
Direct Known Subclasses
Instance Method Summary collapse
-
#attribute(name) ⇒ Object
Defines an attribute.
-
#attribute_names ⇒ Array<Symbol>
The list of attribute names for this Schema.
-
#initialize(*attribute_names) ⇒ Schema
constructor
Sets the Schema’s attribute names.
Constructor Details
#initialize(*attribute_names) ⇒ Schema
Sets the Schema’s attribute names.
15 16 17 |
# File 'lib/upgrow/schema.rb', line 15 def initialize(*attribute_names) @attribute_names = Set.new(attribute_names) end |
Instance Method Details
#attribute(name) ⇒ Object
Defines an attribute.
29 30 31 |
# File 'lib/upgrow/schema.rb', line 29 def attribute(name) @attribute_names += [name] end |
#attribute_names ⇒ Array<Symbol>
The list of attribute names for this Schema.
22 23 24 |
# File 'lib/upgrow/schema.rb', line 22 def attribute_names @attribute_names.to_a end |