class Upgrow::Schema

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.

Public Class Methods

new(*attribute_names) click to toggle source

Sets the Schema's attribute names.

@param attribute_names [Array<Symbol>] the attribute names to be set.

# File lib/upgrow/schema.rb, line 15
def initialize(*attribute_names)
  @attribute_names = Set.new(attribute_names)
end

Public Instance Methods

attribute(name) click to toggle source

Defines an attribute.

@param name [Symbol] the name of the attribute.

# File lib/upgrow/schema.rb, line 29
def attribute(name)
  @attribute_names += [name]
end
attribute_names() click to toggle source

The list of attribute names for this Schema.

@return [Array<Symbol>] the list of attribute names.

# File lib/upgrow/schema.rb, line 22
def attribute_names
  @attribute_names.to_a
end