Sha256: 76be822a2c91f5d936eda3c0052328e67d07158db807cc9d3db5c03eb12f1ea2

Contents?: true

Size: 728 Bytes

Versions: 1

Compression:

Stored size: 728 Bytes

Contents

module Materialize
  class BaseBuilder
    extend Concurrent
    class << self

      def build(data, repo, options)
        attach_builder_info(entity_class.new(data), repo, options)
      end

      def build_all(data, repo, options)
        entity_class.wrap(data).map { |entity| attach_builder_info(entity, repo, options) }
      end

      def entity_class
        "Entities::#{entity_base_class_name}".split('::').reduce(Module, :const_get)
      end

      private

      def attach_builder_info(entity, repo, options)
        entity.__builder_info__ = { repo: repo, options: options }
        entity
      end

      def entity_base_class_name
        "#{self.name[0..-8]}".split('::').last
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
materialize-0.3.0 lib/materialize/base_builder.rb