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.



13
14
15
16
17
18
19
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 13

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.



72
73
74
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 72

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



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

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



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

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

.exec_block(&block) ⇒ Object



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

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

.property(name, options) ⇒ Object



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

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



59
60
61
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 59

def association(_)
  []
end

#changed_attributesObject



52
53
54
55
56
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 52

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

#ldp_connectionObject



41
42
43
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 41

def ldp_connection
  ActiveFedora.fedora.connection
end

#ldp_sourceObject



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

def ldp_source
  @ldp_source ||= LdpResource.new(ldp_connection, )
end

#saveObject



45
46
47
48
49
50
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 45

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

#set_value(*args) ⇒ Object



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

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