Skip to content

OM does not work with elements that have a hyphen #46

@mstroming

Description

@mstroming

Given this terminology:

set_terminology do |t|
  t.root(:path => "orcid-work")
  t.work_title(:path => "work-title")
end

This does not work:
object.work_title = "test title"

This is because Nokogiri does not support this:

xml.work-title("test title")

Instead, it supports:

xml.send(:'work-title', 'test title')

OM is using eval to run a string as a line of code. That line of code is Nokogiri code. We need to convert the string as it is now to use sends. Nested sends might look like this:

b = Nokogiri::XML::Builder.new do |xml|
  xml.send(:'foo-bar') {
    xml.send(:'bar-foo', 'hello')
  }
end

https://github.com/projecthydra/om/blob/v3.0.4/lib/om/xml/term_value_operators.rb#L170
The code that needs to change is around here:
class: lib/om/xml/term_value_operators.rb
method: insert_from_template(parent_node, new_values, template)

builder = Nokogiri::XML::Builder.with(parent_node) do |xml|
      new_values.each do |builder_new_value|
        builder_new_value = builder_new_value.gsub(/'/, "\\\\'") # escape any apostrophes in the new value
        if matchdata = /xml\.@(\w+)/.match(template)
          parent_node.set_attribute(matchdata[1], builder_new_value)
        else
          builder_arg = eval('"'+ template + '"') # this inserts builder_new_value into the builder template
          eval(builder_arg)
        end
      end
    end
    return parent_node
  end

One possible solution is that builder_arg needs to get converted to use sends.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions