Class: FlatMap::OpenMapper
- Inherits:
-
Object
- Object
- FlatMap::OpenMapper
- Extended by:
- ActiveSupport::Autoload
- Includes:
- ActiveModel::Validations, AttributeMethods, Mapping, Mounting, Persistence, Skipping, Traits
- Defined in:
- lib/flat_map/open_mapper.rb
Overview
Base Mapper that can be used for mounting other mappers, handling business logic, etc. For the intentional usage of mappers, pleas see ModelMapper
Direct Known Subclasses
Defined Under Namespace
Modules: AttributeMethods, Mapping, Mounting, Persistence, Skipping, Traits Classes: Factory, NoTargetError
Instance Attribute Summary collapse
-
#host ⇒ FlatMap::Mapper
If mapper was mounted by another mapper, host is the one who mounted
self
. -
#name ⇒ Object
Returns the value of attribute name.
-
#owner ⇒ Object
Returns the value of attribute owner.
-
#suffix ⇒ String?
suffix
reader. -
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#traits ⇒ Object
readonly
Returns the value of attribute traits.
Class Method Summary collapse
-
.inherited(subclass) ⇒ Object
Callback to dup mappings and mountings on inheritance.
Instance Method Summary collapse
-
#hosted? ⇒ Boolean
Return
true
if mapper is hosted, i.e. -
#initialize(target, *traits) ⇒ OpenMapper
constructor
Initializes
mapper
withtarget
andtraits
, which are used to fetch proper list of mounted mappers. -
#inspect ⇒ String
Return a simple string representation of
mapper
. -
#owned? ⇒ Boolean
Return
true
ifmapper
is owned. -
#suffixed? ⇒ Boolean
Return
true
ifsuffix
is present.
Methods included from Skipping
#save, #shallow_save, #skip!, #skipped?, #use!, #valid?, #write
Methods included from Persistence
#apply, #errors, #persisted?, #save, #save_target, #shallow_save, #valid?, #write
Methods included from AttributeMethods
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
#initialize(target, *traits) ⇒ OpenMapper
Initializes mapper
with target
and traits
, which are used to fetch proper list of mounted mappers. Raises error if target is not specified.
56 57 58 59 60 61 62 63 64 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class FlatMap::OpenMapper::AttributeMethods
Instance Attribute Details
#host ⇒ FlatMap::Mapper
If mapper was mounted by another mapper, host is the one who mounted self
.
87 88 89 |
# File 'lib/flat_map/open_mapper.rb', line 87 def host owned? ? owner.host : @host end |
#name ⇒ Object
Returns the value of attribute name.
35 36 37 |
# File 'lib/flat_map/open_mapper.rb', line 35 def name @name end |
#owner ⇒ Object
Returns the value of attribute owner.
35 36 37 |
# File 'lib/flat_map/open_mapper.rb', line 35 def owner @owner end |
#suffix ⇒ String?
suffix
reader. Delegated to owner for owned mappers.
102 103 104 |
# File 'lib/flat_map/open_mapper.rb', line 102 def suffix owned? ? owner.suffix : @suffix end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
34 35 36 |
# File 'lib/flat_map/open_mapper.rb', line 34 def target @target end |
#traits ⇒ Object (readonly)
Returns the value of attribute traits.
34 35 36 |
# File 'lib/flat_map/open_mapper.rb', line 34 def traits @traits end |
Class Method Details
.inherited(subclass) ⇒ Object
44 45 46 47 |
# File 'lib/flat_map/open_mapper.rb', line 44 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.
95 96 97 |
# File 'lib/flat_map/open_mapper.rb', line 95 def hosted? host.present? end |
#inspect ⇒ String
Return a simple string representation of mapper
. Done so to avoid really long inspection of internal objects (target - usually AR model, mountings and mappings)
70 71 72 |
# File 'lib/flat_map/open_mapper.rb', line 70 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.
79 80 81 |
# File 'lib/flat_map/open_mapper.rb', line 79 def owned? owner.present? end |
#suffixed? ⇒ Boolean
Return true
if suffix
is present.
109 110 111 |
# File 'lib/flat_map/open_mapper.rb', line 109 def suffixed? suffix.present? end |