Class: Krikri::MappingDSL::RdfSubjects::SubjectDeclaration

Inherits:
PropertyDeclaration show all
Defined in:
lib/krikri/mapping_dsl/rdf_subjects.rb

Instance Attribute Summary

Attributes inherited from PropertyDeclaration

#name, #value

Instance Method Summary collapse

Methods inherited from PropertyDeclaration

#initialize

Constructor Details

This class inherits a constructor from Krikri::MappingDSL::PropertyDeclaration

Instance Method Details

#to_procObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/krikri/mapping_dsl/rdf_subjects.rb', line 11

def to_proc
  block = @block if @block
  value = @value
  lambda do |target, record|
    value = value.call(record) if value.respond_to? :call
    return target.rdf_subject if Array(value).empty?
    raise "Error mapping #{record}, #{target}\t" \
          "URI must be set to a single value; got #{value}" if
      Array(value).count != 1
    value = value.first if value.is_a? Enumerable
    return target.send(setter, value) unless block
    target.send(setter, instance_exec(value, &block))
  end
end