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.
- #protocol ⇒ Object
-
#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.
134 135 136 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 134 def initialize(id) @id = id end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
133 134 135 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 133 def id @id end |
Instance Method Details
#current? ⇒ Boolean
167 168 169 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 167 def current? version_files.first.id == id end |
#current_reference_id ⇒ Object
142 143 144 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 142 def current_reference_id self.class.new(Valkyrie::ID.new(string_id.gsub(version, "current"))) end |
#deletion_marker? ⇒ Boolean
163 164 165 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 163 def deletion_marker? string_id.include?("deletionmarker") end |
#file_path ⇒ Object
152 153 154 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 152 def file_path @file_path ||= string_id.gsub(/^#{Regexp.escape(protocol)}/, '') end |
#filename ⇒ Object
184 185 186 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 184 def filename string_id.split("v-").last.split("-", 2).last.gsub("deletionmarker-", "") end |
#protocol ⇒ Object
138 139 140 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 138 def protocol PROTOCOL end |
#reference? ⇒ Boolean
Returns Whether this id is referential (e.g. “current”) or absolute (e.g. a timestamp).
172 173 174 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 172 def reference? version == "current" end |
#resolve_current ⇒ VersionID
Returns the version_id for the current file.
147 148 149 150 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 147 def resolve_current return self unless reference? version_files.first end |
#string_id ⇒ Object
188 189 190 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 188 def string_id id.to_s end |
#version ⇒ Object
180 181 182 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 180 def version string_id.split("v-").last.split("-", 2).first end |
#version_files ⇒ Object
156 157 158 159 160 161 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 156 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("#{protocol}#{file}")) end end |
#versioned? ⇒ Boolean
176 177 178 |
# File 'lib/valkyrie/storage/versioned_disk.rb', line 176 def versioned? string_id.include?("v-") end |