Class: Valkyrie::Storage::VersionedDisk::VersionId
- Inherits:
-
Object
- Object
- Valkyrie::Storage::VersionedDisk::VersionId
- Defined in:
- lib/valkyrie/storage/versioned_disk.rb
Overview
A small value class that holds a version id and methods for knowing things about it. Examples of version ids in this adapter:
* "versiondisk://te/st/test/v-current-filename.jpg" (never actually saved this way on disk, just used as a reference)
* "versiondisk://te/st/test/v-1694195675462560794-filename.jpg" (this timestamped form would be saved on disk)
* "versiondisk://te/st/test/v-1694195675462560794-deletionmarker-filename.jpg" (this file is saved on disk but empty)
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #current? ⇒ Boolean
- #current_reference_id ⇒ Object
- #deletion_marker? ⇒ Boolean
- #file_path ⇒ Object
- #filename ⇒ Object
-
#initialize(id) ⇒ VersionId
constructor
A new instance of VersionId.
-
#reference? ⇒ Boolean
Whether this id is referential (e.g. “current”) or absolute (e.g. a timestamp).
-
#resolve_current ⇒ VersionID
The version_id for the current file.
- #string_id ⇒ Object
- #version ⇒ Object
- #version_files ⇒ Object
- #versioned? ⇒ Boolean
Constructor Details
#initialize(id) ⇒ VersionId
Returns a new instance of VersionId.
127 128 129 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 127 def initialize(id) @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
126 127 128 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 126 def id @id end |
Instance Method Details
#current? ⇒ Boolean
156 157 158 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 156 def current? version_files.first.id == id end |
#current_reference_id ⇒ Object
131 132 133 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 131 def current_reference_id self.class.new(Valkyrie::ID.new(string_id.gsub(version, "current"))) end |
#deletion_marker? ⇒ Boolean
152 153 154 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 152 def deletion_marker? string_id.include?("deletionmarker") end |
#file_path ⇒ Object
141 142 143 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 141 def file_path @file_path ||= string_id.gsub(/^versiondisk:\/\//, '') end |
#filename ⇒ Object
173 174 175 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 173 def filename string_id.split("v-").last.split("-", 2).last.gsub("deletionmarker-", "") end |
#reference? ⇒ Boolean
Returns Whether this id is referential (e.g. “current”) or absolute (e.g. a timestamp).
161 162 163 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 161 def reference? version == "current" end |
#resolve_current ⇒ VersionID
Returns the version_id for the current file.
136 137 138 139 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 136 def resolve_current return self unless reference? version_files.first end |
#string_id ⇒ Object
177 178 179 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 177 def string_id id.to_s end |
#version ⇒ Object
169 170 171 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 169 def version string_id.split("v-").last.split("-", 2).first end |
#version_files ⇒ Object
145 146 147 148 149 150 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 145 def version_files root = Pathname.new(file_path) root.parent.children.select { |file| file.basename.to_s.end_with?(filename) }.sort.reverse.map do |file| VersionId.new(Valkyrie::ID.new("versiondisk://#{file}")) end end |
#versioned? ⇒ Boolean
165 166 167 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 165 def versioned? string_id.include?("v-") end |