Sha256: e17a3216574a3345a54c96d9b6892e7327d1c3bd0067a95a6a5e186a4e2606d0

Contents?: true

Size: 1015 Bytes

Versions: 3

Compression:

Stored size: 1015 Bytes

Contents

# frozen_string_literal: true

module Upgrow
  # 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.
  class Schema
    # Sets the Schema's attribute names.
    #
    # @param attribute_names [Array<Symbol>] the attribute names to be set.
    def initialize(*attribute_names)
      @attribute_names = Set.new(attribute_names)
    end

    # The list of attribute names for this Schema.
    #
    # @return [Array<Symbol>] the list of attribute names.
    def attribute_names
      @attribute_names.to_a
    end

    # Defines an attribute.
    #
    # @param name [Symbol] the name of the attribute.
    def attribute(name)
      @attribute_names += [name]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
upgrow-0.0.5 lib/upgrow/schema.rb
upgrow-0.0.4 lib/upgrow/schema.rb
upgrow-0.0.3 lib/upgrow/schema.rb