Class: ActiveFedora::WithMetadata::MetadataNode

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ MetadataNode

Returns a new instance of MetadataNode.



7
8
9
10
11
12
13
14
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 7

def initialize(file)
  @file = file
  super(file.uri, ldp_source.graph)
  if self.class.type && !self.type.include?(self.class.type)
    # Workaround for https://github.com/ActiveTriples/ActiveTriples/issues/123
    self.get_values(:type) << self.class.type
  end
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

Class Method Details

.create_delegating_setter(name) ⇒ Object



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

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

.exec_block(&block) ⇒ Object



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

def exec_block(&block)
  class_eval &block
end

.parent_classObject



69
70
71
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 69

def parent_class
  @parent_class
end

.parent_class=(parent) ⇒ Object



65
66
67
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 65

def parent_class= parent
  @parent_class = parent
end

.property(name, options) ⇒ Object



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

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

Instance Method Details

#changed_attributesObject



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

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

#ldp_connectionObject



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

def ldp_connection
  ActiveFedora.fedora.connection
end

#ldp_sourceObject



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

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

#metadata_uriObject



20
21
22
23
24
25
26
27
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 20

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

#metadata_uri=(uri) ⇒ Object



16
17
18
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 16

def  uri
  @metadata_uri = uri
end

#saveObject



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

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



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

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