Sha256: f500aa1c1fa90f4d9ad8937da955f813074b1cde79134cb110948a1bd767458b

Contents?: true

Size: 1.11 KB

Versions: 32

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module ReeMapper::DSL
  def self.included(base)
    base.extend(ClassMethods)
    base.include(InstanceMethods)
  end

  def self.extended(base)
    base.extend(ClassMethods)
    base.include(InstanceMethods)
  end

  module InstanceMethods
    def build
      self.class.instance_variable_get(:@mapper)
    end
  end

  module ClassMethods
    include Ree::Contracts::Core
    include Ree::Contracts::ArgContracts

    contract Symbol, Optblock => Ree::Object
    def mapper(name, &proc)
      dsl = Ree::ObjectDsl.new(
        Ree.container.packages_facade, name, self, :object
      )

      dsl.instance_exec(&proc) if block_given?
      dsl.factory :build

      Ree.container.compile(dsl.package, name)
    end

    contract(
      Kwargs[
        register_as: Nilor[Symbol]
      ] => ReeMapper::MapperFactoryProxy
    )
    def build_mapper(register_as: nil)
      mapper_factory = ReeMapper.get_mapper_factory(Object.const_get(name.split('::').first))

      mapper_factory.call(register_as: register_as) do |mapper|
        self.instance_variable_set(:@mapper, mapper)
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
ree_lib-1.0.32 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.31 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.30 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.29 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.28 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.27 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.26 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.24 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.23 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.22 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.21 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.20 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.19 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.18 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.17 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.16 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.15 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.14 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.13 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.12 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb