Module: FedoraLens::AttributeMethods::Write

Extended by:
ActiveSupport::Concern
Defined in:
lib/fedora_lens/attribute_methods/write.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

WriterMethodCache =
Class.new(AttributeMethodCache) {
  private

  def method_body(method_name, const_name)
    <<-EOMETHOD
    def #{method_name}(value)
      name = ::FedoraLens::AttributeMethods::AttrNames::ATTR_#{const_name}
      write_attribute(name, value)
    end
    EOMETHOD
  end
}.new

Instance Method Summary collapse

Instance Method Details

#write_attribute(attribute_name, value) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/fedora_lens/attribute_methods/write.rb', line 23

def write_attribute(attribute_name, value)
  if attributes_as_lenses.key?(attribute_name) 
    @attributes[attribute_name] = value
  else
    raise ActiveModel::MissingAttributeError, "can't write unknown attribute `#{attribute_name}'"
  end
end