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


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

def initialize(file)
  @file = file
  super(file.uri, ldp_source.graph)
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


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

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

.exec_block(&block) ⇒ Object


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

def exec_block(&block)
  class_eval &block
end

.parent_classObject


51
52
53
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 51

def parent_class
  @parent_class
end

.parent_class=(parent) ⇒ Object


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

def parent_class= parent
  @parent_class = parent
end

.property(name, options) ⇒ Object


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

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

Instance Method Details

#ldp_connectionObject


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

def ldp_connection
  ActiveFedora.fedora.connection
end

#ldp_sourceObject


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

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

#metadata_uriObject


16
17
18
19
20
21
22
23
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 16

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


12
13
14
# File 'lib/active_fedora/with_metadata/metadata_node.rb', line 12

def  uri
  @metadata_uri = uri
end

#saveObject


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

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

#set_value(*args) ⇒ Object


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

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