Sha256: 1cfea481d2c9d8feeb7247bfb729f7c3ce2b9e91bc1699bf5b07b17cadddd3a4

Contents?: true

Size: 797 Bytes

Versions: 2

Compression:

Stored size: 797 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)
        adapter.attribute_name = name
        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

2 entries across 2 versions & 1 rubygems

Version Path
koine-attributes-1.2.0 lib/koine/attributes/attributes_factory.rb
koine-attributes-1.1.0 lib/koine/attributes/attributes_factory.rb