lib/ddr/models/metadata/metadata.rb in ddr-models-3.0.0.beta.11 vs lib/ddr/models/metadata/metadata.rb in ddr-models-3.0.0.beta.12
- old
+ new
@@ -1,12 +1,31 @@
module Ddr::Models
module Metadata
+ extend ActiveSupport::Concern
+ ADMIN_METADATA = 'admin_metadata'.freeze
+ DESC_METADATA = 'desc_metadata'.freeze
+
+ included do
+ def self.property_term(term)
+ property_terms[term]
+ end
+ end
+
def values(term)
self.send(term)
end
+ # Update singular term with value
+ def set_value(term, value)
+ begin
+ self.send("#{term}=", value)
+ rescue NoMethodError
+ raise ArgumentError, "No such term: #{term}"
+ end
+ end
+
# Update term with values
# Note that empty values (nil or "") are rejected from values array
def set_values(term, values)
if values.respond_to?(:reject!)
values.reject! { |v| v.blank? }
@@ -23,11 +42,16 @@
# Add value to term
# Note that empty value (nil or "") is not added
def add_value(term, value)
begin
unless value.blank?
- values = values(term).to_a << value
- set_values term, values
+ prop_term = self.class.property_term(term)
+ if object.class.properties[prop_term.to_s].multiple?
+ values = values(term).to_a << value
+ set_values term, values
+ else
+ set_value term, value
+ end
end
rescue NoMethodError
raise ArgumentError, "No such term: #{term}"
end
end