Sha256: b6f2f19db793ff3fb4e5d3f9d5b2ea4a7711f324eb7ec58b68229a397d643473

Contents?: true

Size: 1.18 KB

Versions: 34

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module ReeMapper::DSL
  def self.included(base)
    base.extend(ClassMethods)
    base.include(InstanceMethods)
    base.include(Ree::Inspectable)
  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.tags(["object", "mapper"])
      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

34 entries across 34 versions & 1 rubygems

Version Path
ree_lib-1.0.124 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.123 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.122 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.121 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.120 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.119 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.118 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.117 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.116 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.115 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.114 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.113 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.112 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.111 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.110 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.109 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.108 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.107 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.106 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb
ree_lib-1.0.105 lib/ree_lib/packages/ree_mapper/package/ree_mapper/dsl.rb