Sha256: 8722ca47ed4814d0f16a08b9e32dc73998858ab87a9da48ed74f71c44a399415

Contents?: true

Size: 724 Bytes

Versions: 1

Compression:

Stored size: 724 Bytes

Contents

require 'pry'

module Materialize
  class BaseBuilder
    extend Concurrent
    class << self

      # Need to attach builder info somehow before we call initialize!
      def build(data, repo, options)
        data = data.merge({ __repo__: repo, __options__: options })
        entity_class.new(data)
      end

      def build_all(data, repo, options)
        datas = data.map { |d| d.merge({ __repo__: repo, __options__: options }) }
        entity_class.wrap(datas)
      end

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

      private

      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.1 lib/materialize/base_builder.rb