Class: FlatMap::BaseMapper

Inherits:
Object
  • Object
show all
Extended by:
ActiveSupport::Autoload
Includes:
ActiveModel::Validations, AttributeMethods, Mapping, Mounting, Persistence, Skipping, Traits
Defined in:
lib/flat_map/base_mapper.rb

Overview

BaseMapper is an abstract class that hosts overwhelming majority of common functionality of EmptyMappers and Mappers.

For more detailed information on what mappers are, refer to Mapper documentation.

Direct Known Subclasses

EmptyMapper, Mapper

Defined Under Namespace

Modules: AttributeMethods, Mapping, Mounting, Persistence, Skipping, Traits Classes: Factory

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Skipping

#save, #shallow_save, #skip!, #skipped?, #use!, #valid?, #write

Methods included from Persistence

#apply, #errors, #save, #shallow_save, #valid?, #write

Methods included from AttributeMethods

#method_missing

Methods included from Traits

#extension, #extension?, #mountings, #self_mountings, #trait

Methods included from Mounting

#after_save_mountings, #before_save_mountings, #method_missing, #mounting, #mountings, #nearest_mountings, #read, #write

Methods included from Mapping

#[], #[]=, #mapping, #read, #write

Constructor Details

#initializeBaseMapper

Raise exception on trying to initialize an instance.

Raises:

  • (RuntimeError)


44
45
46
# File 'lib/flat_map/base_mapper.rb', line 44

def initialize
  raise 'BaseMapper is abstract class and cannot be initialized'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class FlatMap::BaseMapper::AttributeMethods

Instance Attribute Details

#hostFlatMap::Mapper

If mapper was mounted by another mapper, host is the one who mounted self.

Returns:



69
70
71
# File 'lib/flat_map/base_mapper.rb', line 69

def host
  owned? ? owner.host : @host
end

#nameObject

Returns the value of attribute name.



27
28
29
# File 'lib/flat_map/base_mapper.rb', line 27

def name
  @name
end

#ownerObject

Returns the value of attribute owner.



27
28
29
# File 'lib/flat_map/base_mapper.rb', line 27

def owner
  @owner
end

#suffixString?

suffix reader. Delegated to owner for owned mappers.

Returns:

  • (String, nil)


84
85
86
# File 'lib/flat_map/base_mapper.rb', line 84

def suffix
  owned? ? owner.suffix : @suffix
end

#traitsObject (readonly)

Returns the value of attribute traits.



25
26
27
# File 'lib/flat_map/base_mapper.rb', line 25

def traits
  @traits
end

Class Method Details

.inherited(subclass) ⇒ Object

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.



36
37
38
39
# File 'lib/flat_map/base_mapper.rb', line 36

def self.inherited(subclass)
  subclass.mappings  = mappings.dup
  subclass.mountings = mountings.dup
end

Instance Method Details

#hosted?Boolean

Return true if mapper is hosted, i.e. it is mounted by another mapper.

Returns:

  • (Boolean)


77
78
79
# File 'lib/flat_map/base_mapper.rb', line 77

def hosted?
  host.present?
end

#inspectString

Return a simple string representation of mapper. Done so to avoid really long inspection of internal objects (target - usually AR model, mountings and mappings)

Returns:

  • (String)


52
53
54
# File 'lib/flat_map/base_mapper.rb', line 52

def inspect
  to_s
end

#owned?Boolean

Return true if mapper is owned. This means that current mapper is actually a trait. Thus, it is a part of an owner mapper.

Returns:

  • (Boolean)


61
62
63
# File 'lib/flat_map/base_mapper.rb', line 61

def owned?
  owner.present?
end

#suffixed?Boolean

Return true if suffix is present.

Returns:

  • (Boolean)


91
92
93
# File 'lib/flat_map/base_mapper.rb', line 91

def suffixed?
  suffix.present?
end