Module: Flatter::Mapper::Target

Extended by:
ActiveSupport::Concern
Included in:
Flatter::Mapper
Defined in:
lib/flatter/mapper/target.rb

Defined Under Namespace

Modules: FactoryMethods

Constant Summary collapse

NoTargetError =
Class.new(ArgumentError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#factoryObject

Returns the value of attribute factory.



28
29
30
# File 'lib/flatter/mapper/target.rb', line 28

def factory
  @factory
end

Instance Method Details

#default_target_class_nameObject



80
81
82
# File 'lib/flatter/mapper/target.rb', line 80

def default_target_class_name
  self.class.name.sub 'Mapper', ''
end

#initialize(target = nil) ⇒ Object



30
31
32
33
# File 'lib/flatter/mapper/target.rb', line 30

def initialize(target = nil, *)
  super
  set_target!(target) if target.present?
end

#set_target(target) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/flatter/mapper/target.rb', line 53

def set_target(target)
  if trait?
    mounter.set_target!(target)
  else
    set_target!(target)
    trait_mountings.each{ |trait| trait.set_target!(target) }
  end
end

#set_target!(target) ⇒ Object



62
63
64
65
66
# File 'lib/flatter/mapper/target.rb', line 62

def set_target!(target)
  fail NoTargetError, "Cannot set nil target for #{self.class.name}" if target.nil?
  @_target_initialized = true
  @target = target
end

#targetObject



35
36
37
38
# File 'lib/flatter/mapper/target.rb', line 35

def target
  ensure_target!
  @target
end

#target_classObject



72
73
74
# File 'lib/flatter/mapper/target.rb', line 72

def target_class
  target_class_name.constantize
end

#target_class_nameObject



76
77
78
# File 'lib/flatter/mapper/target.rb', line 76

def target_class_name
  options[:target_class_name] || default_target_class_name
end

#target_initialized?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/flatter/mapper/target.rb', line 68

def target_initialized?
  !!@_target_initialized
end