Class: Alephant::Publisher::Request::DataMapperFactory

Inherits:
Object
  • Object
show all
Includes:
LogHelper
Defined in:
lib/alephant/publisher/request/data_mapper_factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LogHelper

#log_error_with_metric

Constructor Details

#initialize(connection, base_path) ⇒ DataMapperFactory

Returns a new instance of DataMapperFactory.



11
12
13
14
15
# File 'lib/alephant/publisher/request/data_mapper_factory.rb', line 11

def initialize(connection, base_path)
  @connection = connection
  @base_path  = base_path
  raise InvalidComponentBasePath, base_path unless File.directory? base_path
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



9
10
11
# File 'lib/alephant/publisher/request/data_mapper_factory.rb', line 9

def base_path
  @base_path
end

#connectionObject (readonly)

Returns the value of attribute connection.



9
10
11
# File 'lib/alephant/publisher/request/data_mapper_factory.rb', line 9

def connection
  @connection
end

Instance Method Details

#create(component_id, context = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/alephant/publisher/request/data_mapper_factory.rb', line 17

def create(component_id, context = {})
  require base_path_for component_id

  klass = mapper_class_for(component_id)
  klass.new(connection, context)
rescue LoadError => e
  log_error_with_metric(e, component_id, "PublisherRequestDataMapperFactoryInvalidComponentName")
  raise InvalidComponentName, "Invalid component name: #{component_id}"
rescue NameError => e
  log_error_with_metric(e, component_id, "PublisherRequestDataMapperFactoryInvalidComponentClassName")
  raise InvalidComponentClassName, "Invalid class name #{klass}"
rescue => e
  log_error_with_metric(e, component_id, "PublisherRequestDataMapperFactoryInvalidComponent")
  raise InvalidComponent, "Name: #{component_id}, Class: #{klass}"
end