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

host[W]
name[RW]
owner[RW]
suffix[W]
target[R]
traits[R]

Public Class Methods

inherited(subclass) click to toggle source

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
new(target, *traits) click to toggle source

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

host() click to toggle source

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
hosted?() click to toggle source

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
inspect() click to toggle source

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
owned?() click to toggle source

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() click to toggle source

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
suffixed?() click to toggle source

Return true if suffix is present.

@return [Boolean]

# File lib/flat_map/open_mapper.rb, line 109
def suffixed?
  suffix.present?
end