Sha256: c8a1be10f33e072bd18730561711c5554ddb19092dff7c12656319852ad0328e

Contents?: true

Size: 1.56 KB

Versions: 4

Compression:

Stored size: 1.56 KB

Contents

class StoreSchema::Configuration

  # @return [Symbol]
  #
  attr_reader :column

  # @return [Hash]
  #
  attr_reader :attributes

  # @param column [Symbol] the table column to generate the accessors for
  #
  def initialize(column)
    @column = column
    @attributes = {}
  end

  # @param attribute [Symbol] the name of the attribute on {#column}
  #   for which to generate a String-type accessor
  #
  def string(attribute)
    attributes[attribute] = :string
  end

  # @param attribute [Symbol] the name of the attribute on {#column}
  #   for which to generate an Integer-type accessor
  #
  def integer(attribute)
    attributes[attribute] = :integer
  end

  # @param attribute [Symbol] the name of the attribute on {#column}
  #   for which to generate a Float-type accessor
  #
  def float(attribute)
    attributes[attribute] = :float
  end

  # @param attribute [Symbol] the name of the attribute on {#column}
  #   for which to generate a DateTime-type accessor
  #
  def datetime(attribute)
    attributes[attribute] = :datetime
  end

  # @param attribute [Symbol] the name of the attribute on {#column}
  #   for which to generate a Boolean-type accessor
  #
  def boolean(attribute)
    attributes[attribute] = :boolean
  end

  private

  # Iterates over all defined {#attributes} and defines the
  # necessary accessors for them.
  #
  # @param klass [Class] the class to define the accessors on
  #
  def configure(klass)
    attributes.each do |attribute, type|
      StoreSchema::AccessorDefiner
        .new(klass, column, type, attribute).define
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
store_schema-1.0.1 lib/store_schema/configuration.rb
store_schema-1.0.0 lib/store_schema/configuration.rb
store_schema-0.1.0 lib/store_schema/configuration.rb
store_schema-0.0.1 lib/store_schema/configuration.rb