Class: Hydra::RemoteIdentifier::Mapper::Map

Inherits:
BasicObject
Defined in:
lib/hydra/remote_identifier/mapper.rb

Overview

The Map is responsible for defining which attributes on the target map to the attributes expected in the RemoteService as well as defining how the RemoteService can update the target

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service_class, &config) ⇒ Map

Returns a new instance of Map.



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/hydra/remote_identifier/mapper.rb', line 69

def initialize(service_class, &config)
  @service_class = service_class
  @_setter = nil
  @_getters = {}
  @errors = []
  config.call(self)
  if @_setter.nil?
    @errors << "Missing :set_identifier"
  end
  ::Kernel.raise ::Hydra::RemoteIdentifier::InvalidServiceMapping.new(@errors) if @errors.any?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/hydra/remote_identifier/mapper.rb', line 85

def method_missing(method_name, *args, &block)
  if method_name == :set_identifier
    @_setter = args.first || block
  elsif service_class.valid_attribute?(method_name)
    @_getters[method_name] = args.first || block
  else
    @errors << "Invalid mapping #{method_name}"
  end
end

Instance Attribute Details

#_gettersObject (readonly)

Returns the value of attribute _getters.



68
69
70
# File 'lib/hydra/remote_identifier/mapper.rb', line 68

def _getters
  @_getters
end

#_setterObject (readonly)

Returns the value of attribute _setter.



68
69
70
# File 'lib/hydra/remote_identifier/mapper.rb', line 68

def _setter
  @_setter
end

#service_classObject (readonly)

Returns the value of attribute service_class.



68
69
70
# File 'lib/hydra/remote_identifier/mapper.rb', line 68

def service_class
  @service_class
end

Instance Method Details

#inspectObject



81
82
83
# File 'lib/hydra/remote_identifier/mapper.rb', line 81

def inspect
  "#<Hydra::RemoteIdentifier::Mapper::Map for #{service_class} (#{__FILE__})>"
end