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.



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

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.



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

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



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

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



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

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

.exec_block(&block) ⇒ Object



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

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

.property(name, options) ⇒ Object



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

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

Instance Method Details

#changed_attributesObject



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

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

#ldp_connectionObject



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

def ldp_connection
  ActiveFedora.fedora.connection
end

#ldp_sourceObject



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

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

#saveObject



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

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



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

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