Class: Upgrow::Schema

Inherits:
Object
  • Object
show all
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

ModelSchema

Instance Method Summary collapse

Constructor Details

#initialize(*attribute_names) ⇒ Schema

Sets the Schema’s attribute names.

Parameters:

  • attribute_names (Array<Symbol>)

    the attribute names to be set.



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.

Parameters:

  • name (Symbol)

    the name of the attribute.



29
30
31
# File 'lib/upgrow/schema.rb', line 29

def attribute(name)
  @attribute_names += [name]
end

#attribute_namesArray<Symbol>

The list of attribute names for this Schema.

Returns:

  • (Array<Symbol>)

    the list of attribute names.



22
23
24
# File 'lib/upgrow/schema.rb', line 22

def attribute_names
  @attribute_names.to_a
end