Class: Flatter::Mapper::Factory

Inherits:
Object
  • Object
show all
Includes:
Collection::FactoryMethods, Mounting::FactoryMethods, Options::FactoryMethods, Target::FactoryMethods, Traits::FactoryMethods
Defined in:
lib/flatter/mapper/factory.rb

Constant Summary collapse

NoTargetError =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Attributes included from Traits::FactoryMethods

#extension

Instance Method Summary collapse

Methods included from Traits::FactoryMethods

#trait?, #traits

Methods included from Collection::FactoryMethods

#collection?

Constructor Details

#initialize(name, **options) ⇒ Factory

Returns a new instance of Factory.



13
14
15
# File 'lib/flatter/mapper/factory.rb', line 13

def initialize(name, **options)
  @name, @options = name.to_s, options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/flatter/mapper/factory.rb', line 11

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/flatter/mapper/factory.rb', line 11

def options
  @options
end

Instance Method Details

#createObject



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

def create(*)
  mapper_class.new.tap{ |mapper| mapper.factory = self }
end

#default_mapper_class_nameObject



32
33
34
# File 'lib/flatter/mapper/factory.rb', line 32

def default_mapper_class_name
  "#{name.camelize}Mapper"
end

#fetch_target_from(mapper) ⇒ Object



49
50
51
# File 'lib/flatter/mapper/factory.rb', line 49

def fetch_target_from(mapper)
  default_target_from(mapper)
end

#mapper_classObject



17
18
19
# File 'lib/flatter/mapper/factory.rb', line 17

def mapper_class
  options[:mapper_class] || default_mapper_class
end

#mapper_class_nameObject



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

def mapper_class_name
  options[:mapper_class_name] || modulize(default_mapper_class_name)
end