class ActiveFedora::WithMetadata::MetadataNode
Attributes
parent_class[RW]
file[R]
metadata_uri[W]
Public Class Methods
create_delegating_setter(name)
click to toggle source
# File lib/active_fedora/with_metadata/metadata_node.rb, line 87 def create_delegating_setter(name) file.class.delegate(name, to: :metadata_node) end
exec_block(&block)
click to toggle source
# File lib/active_fedora/with_metadata/metadata_node.rb, line 91 def exec_block(&block) class_eval(&block) end
new(file)
click to toggle source
@param file [ActiveFedora::File]
Calls superclass method
# File lib/active_fedora/with_metadata/metadata_node.rb, line 14 def initialize(file) @file = file super(file.uri, ldp_source.graph) return unless self.class.type && !type.include?(self.class.type) attribute_will_change!(:type) if type.present? # Workaround for https://github.com/ActiveTriples/ActiveTriples/issues/123 get_values(:type) << self.class.type end
property(name, options)
click to toggle source
Calls superclass method
# File lib/active_fedora/with_metadata/metadata_node.rb, line 82 def property(name, options) parent_class.delegate name, :"#{name}=", :"#{name}_changed?", to: :metadata_node super end
Public Instance Methods
association(_)
click to toggle source
Conform to the ActiveFedora::Base
API
# File lib/active_fedora/with_metadata/metadata_node.rb, line 63 def association(_) [] end
changed_attributes()
click to toggle source
Calls superclass method
# File lib/active_fedora/with_metadata/metadata_node.rb, line 56 def changed_attributes super.tap do |changed| changed.merge('type' => true) if type.present? && new_record? end end
ldp_connection()
click to toggle source
# File lib/active_fedora/with_metadata/metadata_node.rb, line 44 def ldp_connection ActiveFedora.fedora.connection end
ldp_source()
click to toggle source
# File lib/active_fedora/with_metadata/metadata_node.rb, line 39 def ldp_source @ldp_source ||= LdpResource.new(ldp_connection, nil) if file.new_record? @ldp_source ||= LdpResource.new(ldp_connection, metadata_uri) end
metadata_uri()
click to toggle source
# File lib/active_fedora/with_metadata/metadata_node.rb, line 25 def metadata_uri @metadata_uri ||= if file.new_record? ::RDF::URI.new nil else raise "#{file} must respond_to described_by" unless file.respond_to? :described_by file.described_by end end
save()
click to toggle source
# File lib/active_fedora/with_metadata/metadata_node.rb, line 48 def save raise "Save the file first" if file.new_record? SparqlInsert.new(changes_for_update, file.uri).execute(metadata_uri) @ldp_source = nil @metadata_uri = nil true end
set_value(*args)
click to toggle source
Calls superclass method
# File lib/active_fedora/with_metadata/metadata_node.rb, line 34 def set_value(*args) super attribute_will_change! args.first unless server_managed_properties.include?(args.first) end
Private Instance Methods
changes_for_update()
click to toggle source
# File lib/active_fedora/with_metadata/metadata_node.rb, line 69 def changes_for_update ChangeSet.new(self, self, changed_attributes.keys).changes end
server_managed_properties()
click to toggle source
# File lib/active_fedora/with_metadata/metadata_node.rb, line 73 def server_managed_properties @server_managed_properties ||= properties.select { |_k, v| v[:server_managed] }.keys.map(&:to_sym) end