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.



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

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



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

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.



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

def _getters
  @_getters
end

#_setterObject (readonly)

Returns the value of attribute _setter.



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

def _setter
  @_setter
end

#service_classObject (readonly)

Returns the value of attribute service_class.



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

def service_class
  @service_class
end

Instance Method Details

#inspectObject



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

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