Module: ReeMapper

Includes:
Ree::PackageDSL
Defined in:
lib/ree_lib/packages/ree_mapper/package/ree_mapper.rb

Defined Under Namespace

Modules: DSL Classes: AbstractType, AbstractWrapper, Any, ArgumentError, Array, Bool, BuildMapperFactory, BuildMapperStrategy, CoercionError, Date, DateTime, DefaultFactory, Error, ErrorWithLocation, Field, FieldsFilter, FilterFieldsContract, Float, HashOutput, Integer, Mapper, MapperFactory, MapperFactoryProxy, MapperStrategy, ObjectOutput, Rational, ReeDtoOutput, StrategyOutput, String, StructOutput, Time, TypeError, UnsupportedTypeError

Class Method Summary collapse

Class Method Details

.get_mapper_factory(mod) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ree_lib/packages/ree_mapper/package/ree_mapper.rb', line 56

def self.get_mapper_factory(mod)
  if !mod.is_a?(Module)
    raise Ree::Error.new("module should be provided", :invalid_dsl_usage)
  end

  if mod.name.nil?
    raise Ree::Error.new("anonymous modules are not supported", :invalid_dsl_usage)
  end

  if mod.name.split('::').size > 1
    raise Ree::Error.new("top level module should be provided", :invalid_dsl_usage)
  end

  factory = mod.instance_variable_get(:@mapper_factory)
  return factory if factory

  if !mod.instance_variable_get(:@mapper_semaphore)
    mod.instance_variable_set(:@mapper_semaphore, Mutex.new)
  end

  mod.instance_variable_get(:@mapper_semaphore).synchronize do
    factory = self.build_mapper_factory(mod)
    mod.instance_variable_set(:@mapper_factory, factory)
  end

  factory
end