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.



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

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.



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

def parent_class
  @parent_class
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



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

def file
  @file
end

#metadata_uriObject



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

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



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

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

.exec_block(&block) ⇒ Object



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

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

.property(name, options) ⇒ Object



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

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

Instance Method Details

#changed_attributesObject



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

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

#ldp_connectionObject



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

def ldp_connection
  ActiveFedora.fedora.connection
end

#ldp_sourceObject



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

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

#saveObject



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

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



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

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