Sha256: 836cc26538f995b40679c1296cef1499a745d687a8d7e6700cbdc534cbec1f9c

Contents?: true

Size: 991 Bytes

Versions: 3

Compression:

Stored size: 991 Bytes

Contents

module PgSerializable
  class Trait
    attr_reader :klass, :attribute_nodes

    def initialize(klass)
      @klass = klass
      @attribute_nodes = []
    end

    def attributes(*attrs)
      attrs.each do |attribute|
        @attribute_nodes << Nodes::Attribute.new(klass, attribute)
      end
    end

    def attribute(column_name, label: nil, &blk)
      @attribute_nodes << Nodes::Attribute.new(klass, column_name, label: label, &blk)
    end

    def has_many(association, label: nil, trait: :default)
      @attribute_nodes << Nodes::Association.new(klass, association, :has_many, label: label, trait: trait)
    end

    def belongs_to(association, label: nil, trait: :default)
      @attribute_nodes << Nodes::Association.new(klass, association, :belongs_to, label: label, trait: trait)
    end

    def has_one(association, label: nil, trait: :default)
      @attribute_nodes << Nodes::Association.new(klass, association, :has_one, label: label, trait: trait)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pg_serializable-1.1.0 lib/pg_serializable/trait.rb
pg_serializable-1.0.1 lib/pg_serializable/trait.rb
pg_serializable-1.0.0 lib/pg_serializable/trait.rb