Sha256: f8df43df3b18246d7ad6c9e22884a027f92ef97ce6714360b34635874c331b46

Contents?: true

Size: 1.17 KB

Versions: 14

Compression:

Stored size: 1.17 KB

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

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
pg_serializable-3.1.0 lib/pg_serializable/trait.rb
pg_serializable-3.0.2 lib/pg_serializable/trait.rb
pg_serializable-3.0.1 lib/pg_serializable/trait.rb
pg_serializable-3.0.0 lib/pg_serializable/trait.rb
pg_serializable-2.1.1 lib/pg_serializable/trait.rb
pg_serializable-2.1.0 lib/pg_serializable/trait.rb
pg_serializable-2.0.0 lib/pg_serializable/trait.rb
pg_serializable-1.4.0 lib/pg_serializable/trait.rb
pg_serializable-1.3.2 lib/pg_serializable/trait.rb
pg_serializable-1.3.1 lib/pg_serializable/trait.rb
pg_serializable-1.3.0 lib/pg_serializable/trait.rb
pg_serializable-1.2.2 lib/pg_serializable/trait.rb
pg_serializable-1.2.1 lib/pg_serializable/trait.rb
pg_serializable-1.2.0 lib/pg_serializable/trait.rb