Sha256: 8934637fcbf9710671c63d5385243ac9e4a468cb8fe6d72ead90ffcd14d4e670

Contents?: true

Size: 730 Bytes

Versions: 17

Compression:

Stored size: 730 Bytes

Contents

module PgSerializable
  class TraitManager
    include PgSerializable::Visitable

    attr_reader :klass, :traits

    def initialize(klass)
      @klass = klass
      @traits = ActiveSupport::HashWithIndifferentAccess.new
    end

    def default(&blk)
      default_trait = PgSerializable::Trait.new(klass)
      default_trait.instance_eval &blk
      @traits[:default] = default_trait
    end

    def trait(trait_name, &blk)
      trait_instance = PgSerializable::Trait.new(klass)
      trait_instance.instance_eval &blk
      @traits[trait_name] = trait_instance
    end

    def get_trait(trait)
      @traits[trait]
    end

    def validate_traits!
      accept(PgSerializable::Visitors::Validation.new)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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