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