Class: ActiveFedora::WithMetadata::MetadataNode

Inherits:
ActiveTriples::Resource
  • Object
show all
Includes:
ActiveModel::Dirty
Defined in:
lib/active_fedora/with_metadata/metadata_node.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ MetadataNode

Returns a new instance of MetadataNode.

Parameters:



14
15
16
17
18
19
20
# 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)
  # Workaround for https://github.com/ActiveTriples/ActiveTriples/issues/123
  get_values(:type) << self.class.type
end

Class Attribute Details

.parent_classObject

Returns the value of attribute parent_class.



75
76
77
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 75

def parent_class
  @parent_class
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 5

def file
  @file
end

#metadata_uriObject



24
25
26
27
28
29
30
31
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 24

def 
  @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

Class Method Details

.create_delegating_setter(name) ⇒ Object



82
83
84
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 82

def create_delegating_setter(name)
  file.class.delegate(name, to: :metadata_node)
end

.exec_block(&block) ⇒ Object



86
87
88
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 86

def exec_block(&block)
  class_eval(&block)
end

.property(name, options) ⇒ Object



77
78
79
80
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 77

def property(name, options)
  parent_class.delegate name, :"#{name}=", :"#{name}_changed?", to: :metadata_node
  super
end

Instance Method Details

#association(_) ⇒ Object

Conform to the ActiveFedora::Base API



62
63
64
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 62

def association(_)
  []
end

#changed_attributesObject



55
56
57
58
59
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 55

def changed_attributes
  super.tap do |changed|
    changed['type'] = true if type.present? && new_record?
  end
end

#ldp_connectionObject



43
44
45
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 43

def ldp_connection
  ActiveFedora.fedora.connection
end

#ldp_sourceObject



38
39
40
41
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 38

def ldp_source
  @ldp_source ||= LdpResource.new(ldp_connection, nil) if file.new_record?
  @ldp_source ||= LdpResource.new(ldp_connection, )
end

#saveObject



47
48
49
50
51
52
53
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 47

def save
  raise "Save the file first" if file.new_record?
  SparqlInsert.new(changes_for_update, file.uri).execute()
  @ldp_source = nil
  @metadata_uri = nil
  true
end

#set_value(*args) ⇒ Object



33
34
35
36
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 33

def set_value(*args)
  super
  attribute_will_change! args.first
end