class FlatMap::OpenMapper
Base Mapper
that can be used for mounting other mappers, handling business logic, etc. For the intentional usage of mappers, pleas see {ModelMapper}
Attributes
Public Class Methods
Callback to dup mappings and mountings on inheritance. The values are cloned from actual mappers (i.e. something like CustomerAccountMapper, since it is useless to clone empty values of FlatMap::Mapper
).
Note: those class attributes are defined in {Mapping} and {Mounting} modules.
# File lib/flat_map/open_mapper.rb, line 44 def self.inherited(subclass) subclass.mappings = mappings.dup subclass.mountings = mountings.dup end
Initializes mapper
with target
and traits
, which are used to fetch proper list of mounted mappers. Raises error if target is not specified.
@param [Object] target Target of mapping @param [*Symbol] traits List of traits @raise [FlatMap::Mapper::NoTargetError]
# File lib/flat_map/open_mapper.rb, line 56 def initialize(target, *traits) raise NoTargetError.new(self.class) unless target.present? @target, @traits = target, traits if block_given? singleton_class.trait :extension, &Proc.new end end
Public Instance Methods
If mapper was mounted by another mapper, host is the one who mounted self
.
@return [FlatMap::Mapper]
# File lib/flat_map/open_mapper.rb, line 87 def host owned? ? owner.host : @host end
Return true
if mapper is hosted, i.e. it is mounted by another mapper.
@return [Boolean]
# File lib/flat_map/open_mapper.rb, line 95 def hosted? host.present? end
Return a simple string representation of mapper
. Done so to avoid really long inspection of internal objects (target - usually AR model, mountings and mappings) @return [String]
# File lib/flat_map/open_mapper.rb, line 70 def inspect to_s end
Return true
if mapper
is owned. This means that current mapper is actually a trait. Thus, it is a part of an owner mapper.
@return [Boolean]
# File lib/flat_map/open_mapper.rb, line 79 def owned? owner.present? end
suffix
reader. Delegated to owner for owned mappers.
@return [String, nil]
# File lib/flat_map/open_mapper.rb, line 102 def suffix owned? ? owner.suffix : @suffix end
Return true
if suffix
is present.
@return [Boolean]
# File lib/flat_map/open_mapper.rb, line 109 def suffixed? suffix.present? end