Sha256: d1d2c7161307cdff626b8c98442c66adc9295fa3630c1bf9521ed9ebb1aaad55

Contents?: true

Size: 759 Bytes

Versions: 9

Compression:

Stored size: 759 Bytes

Contents

module Koine
  module Attributes
    class AttributesFactory
      def initialize(options = {})
        @adapters = {}
        @options = options
      end

      def create(target_object)
        Attributes.new(target_object, adapters: @adapters, options: @options)
      end

      def add_attribute(name, adapter, &block)
        adapter = coerce_adapter(adapter)
        yield(adapter) if block
        @adapters[name.to_sym] = adapter.freeze
      end

      def coerce_adapter(adapter)
        return adapter unless adapter.instance_of?(::Symbol)
        Object.const_get("Koine::Attributes::Adapter::#{adapter.to_s.capitalize}").new
      end

      def freeze
        super
        @adapters.freeze
        @options.freeze
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
koine-attributes-1.0.0 lib/koine/attributes/attributes_factory.rb
koine-attributes-0.4.0 lib/koine/attributes/attributes_factory.rb
koine-attributes-0.3.2 lib/koine/attributes/attributes_factory.rb
koine-attributes-0.3.1 lib/koine/attributes/attributes_factory.rb
koine-attributes-0.3.0 lib/koine/attributes/attributes_factory.rb
koine-attributes-0.2.3 lib/koine/attributes/attributes_factory.rb
koine-attributes-0.2.2 lib/koine/attributes/attributes_factory.rb
koine-attributes-0.2.1 lib/koine/attributes/attributes_factory.rb
koine-attributes-0.2.0 lib/koine/attributes/attributes_factory.rb