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
21
# 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

Class Attribute Details

.parent_classObject

Returns the value of attribute parent_class.



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

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



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

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



87
88
89
# 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) ⇒ Object



91
92
93
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 91

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

.property(name, options) ⇒ Object



82
83
84
85
# 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

Instance Method Details

#association(_) ⇒ Object

Conform to the ActiveFedora::Base API



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

def association(_)
  []
end

#changed_attributesObject



56
57
58
59
60
# 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_connectionObject



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

def ldp_connection
  ActiveFedora.fedora.connection
end

#ldp_sourceObject



39
40
41
42
# 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, )
end

#saveObject



48
49
50
51
52
53
54
# 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()
  @ldp_source = nil
  @metadata_uri = nil
  true
end

#set_value(*args) ⇒ Object



34
35
36
37
# 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