Class: OcflTools::OcflActions

Inherits:
Object
  • Object
show all
Defined in:
lib/ocfl_tools/ocfl_actions.rb

Overview

Class for collating manifest actions, both for delta reporting and staging new versions.

Instance Method Summary collapse

Constructor Details

#initializeOcflActions

Returns a new instance of OcflActions.



6
7
8
9
10
11
12
13
14
# File 'lib/ocfl_tools/ocfl_actions.rb', line 6

def initialize
  @my_actions                    = {}
  @my_actions['update_manifest'] = {}
  @my_actions['add']             = {}
  @my_actions['update']          = {}
  @my_actions['copy']            = {}
  @my_actions['move']            = {}
  @my_actions['delete']          = {}
end

Instance Method Details

#actionsHash

Convenience method for obtaining a hash of recorded actions.

Returns:

  • (Hash)

    of actions stored in this instance.



18
19
20
21
22
# File 'lib/ocfl_tools/ocfl_actions.rb', line 18

def actions
  # Don't return empty keys.
  @my_actions.delete_if { |_k, v| v == {} }
  @my_actions
end

#add(digest, filepath) ⇒ Hash

Creates an ‘add’ entry in the actions hash.

Parameters:

  • digest (String)

    of the filepath being recorded.

  • filepath (Pathname)

    of file to record.

Returns:

  • (Hash)

    of recorded action.



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ocfl_tools/ocfl_actions.rb', line 52

def add(digest, filepath)
  if @my_actions['add'].key?(digest) == false
    @my_actions['add'][digest] = []
  end
  # Only put unique values into filepaths
  if @my_actions['add'][digest].include?(filepath)
    return @my_actions['add'][digest]
  else
    @my_actions['add'][digest] = (@my_actions['add'][digest] << filepath)
  end
end

#allHash

Convenience method for obtaining a hash recorded of actions.

Returns:

  • (Hash)

    of actions stored in this instance.



26
27
28
29
30
# File 'lib/ocfl_tools/ocfl_actions.rb', line 26

def all
  # Don't return empty keys.
  @my_actions.delete_if { |_k, v| v == {} }
  @my_actions
end

#copy(digest, filepath) ⇒ Hash

Creates a ‘copy’ entry in the actions hash.

Parameters:

  • digest (String)

    of the filepath being recorded.

  • filepath (Pathname)

    of file to record.

Returns:

  • (Hash)

    of recorded action.



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ocfl_tools/ocfl_actions.rb', line 84

def copy(digest, filepath)
  if @my_actions['copy'].key?(digest) == false
    @my_actions['copy'][digest] = []
  end
  # Only put unique values into filepaths
  if @my_actions['copy'][digest].include?(filepath)
    return @my_actions['copy'][digest]
  else
    @my_actions['copy'][digest] = (@my_actions['copy'][digest] << filepath)
  end
end

#delete(digest, filepath) ⇒ Hash

Creates a ‘delete’ entry in the actions hash.

Parameters:

  • digest (String)

    of the filepath being recorded.

  • filepath (Pathname)

    of file to record.

Returns:

  • (Hash)

    of recorded action.



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ocfl_tools/ocfl_actions.rb', line 116

def delete(digest, filepath)
  if @my_actions['delete'].key?(digest) == false
    @my_actions['delete'][digest] = []
  end
  # Only put unique values into filepaths
  if @my_actions['delete'][digest].include?(filepath)
    return @my_actions['delete'][digest]
  else
    @my_actions['delete'][digest] = (@my_actions['delete'][digest] << filepath)
  end
end

#fixity(digest, fixity_algorithm, fixity_digest) ⇒ Hash

Returns of recorded fixity block.

Parameters:

  • digest (String)

    of the filepath that is getting additional fixity values.

  • fixity_algorithm (String)

    of the fixity digest being added (e.g. ‘md5’, ‘sha1’).

  • fixity_digest (String)

    to associate with this digest.

Returns:

  • (Hash)

    of recorded fixity block.



132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/ocfl_tools/ocfl_actions.rb', line 132

def fixity(digest, fixity_algorithm, fixity_digest)
  # Only create this key if used.
  @my_actions['fixity'] = {} if @my_actions.key?('fixity') == false
  if @my_actions['fixity'].key?(fixity_algorithm) == false
    @my_actions['fixity'][fixity_algorithm] = {}
  end
  # only add unique fixity digests.
  if @my_actions['fixity'][fixity_algorithm].include?(digest)
    return @my_actions['fixity'][fixity_algorithm][digest]
  else
    @my_actions['fixity'][fixity_algorithm][digest] = fixity_digest
  end
end

#move(digest, filepath) ⇒ Hash

Creates a ‘move’ entry in the actions hash.

Parameters:

  • digest (String)

    of the filepath being recorded.

  • filepath (Pathname)

    of file to record.

Returns:

  • (Hash)

    of recorded action.



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ocfl_tools/ocfl_actions.rb', line 100

def move(digest, filepath)
  if @my_actions['move'].key?(digest) == false
    @my_actions['move'][digest] = []
  end
  # Only put unique values into filepaths
  if @my_actions['move'][digest].include?(filepath)
    return @my_actions['move'][digest]
  else
    @my_actions['move'][digest] = (@my_actions['move'][digest] << filepath)
  end
end

#update(digest, filepath) ⇒ Hash

Creates an ‘update’ entry in the actions hash.

Parameters:

  • digest (String)

    of the filepath being recorded.

  • filepath (Pathname)

    of file to record.

Returns:

  • (Hash)

    of recorded action.



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ocfl_tools/ocfl_actions.rb', line 68

def update(digest, filepath)
  if @my_actions['update'].key?(digest) == false
    @my_actions['update'][digest] = []
  end
  # Only put unique values into filepaths
  if @my_actions['update'][digest].include?(filepath)
    return @my_actions['update'][digest]
  else
    @my_actions['update'][digest] = (@my_actions['update'][digest] << filepath)
  end
end

#update_manifest(digest, filepath) ⇒ Hash

Creates an ‘update_manifest’ entry in the actions hash.

Parameters:

  • digest (String)

    of the filepath being recorded.

  • filepath (Pathname)

    of file to record.

Returns:

  • (Hash)

    of recorded action.



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ocfl_tools/ocfl_actions.rb', line 36

def update_manifest(digest, filepath)
  if @my_actions['update_manifest'].key?(digest) == false
    @my_actions['update_manifest'][digest] = []
  end
  # Only put unique values into filepaths
  if @my_actions['update_manifest'][digest].include?(filepath)
    return @my_actions['update_manifest'][digest]
  else
    @my_actions['update_manifest'][digest] = (@my_actions['update_manifest'][digest] << filepath)
  end
end