Class: FilePipeline::Versions::History
- Inherits:
-
Object
- Object
- FilePipeline::Versions::History
- Defined in:
- lib/file_pipeline/versions/history.rb
Overview
History objects keep track of a VersionedFile instances versions names and any associated logs or data for each version.
Instance Method Summary collapse
-
#[](version_name) ⇒ Object
Retrieves the results object for the
version_name. -
#[]=(version_name, results) ⇒ Object
Associates the
resultswith theversion_name. -
#captured_data ⇒ Object
Returns a two-dimensional array, where each nested array has two items: * the file operation object * data captured by the operartion (if any).
-
#captured_data_for(operation_name, **options) ⇒ Object
Returns any data captured by
operation_name. -
#captured_data_with(tag) ⇒ Object
Returns an array with all data captured by operations with
tag. -
#clear! ⇒ Object
Clears all history entries (version names and associated results).
-
#empty? ⇒ Boolean
Returns
trueifselfhas no entries (version names and associated results),trueotherwise. -
#initialize ⇒ History
constructor
Returns a new instance.
-
#log ⇒ Object
Returns an array of triplets (arryas with three items each): * Name of the file operation class (String).
-
#to_a ⇒ Object
Returns a two-dimensional Array where every nested Array will consist of the version name (file path) at index
0andnilor an Array with all results objects for the version at index1:. -
#versions ⇒ Object
Returns an array with paths to the version files of
self(excluding #original).
Constructor Details
#initialize ⇒ History
Returns a new instance.
9 10 11 |
# File 'lib/file_pipeline/versions/history.rb', line 9 def initialize @entries = {} end |
Instance Method Details
#[](version_name) ⇒ Object
Retrieves the results object for the version_name.
14 15 16 |
# File 'lib/file_pipeline/versions/history.rb', line 14 def [](version_name) @entries[version_name] end |
#[]=(version_name, results) ⇒ Object
Associates the results with the version_name.
19 20 21 22 23 |
# File 'lib/file_pipeline/versions/history.rb', line 19 def []=(version_name, results) entry = @entries.fetch version_name, [] entry << results @entries[version_name] = entry.compact end |
#captured_data ⇒ Object
Returns a two-dimensional array, where each nested array has two items:
-
the file operation object
-
data captured by the operartion (if any).
[[file_operation_object, data_or_nil], ...]
30 31 32 |
# File 'lib/file_pipeline/versions/history.rb', line 30 def captured_data filter :data end |
#captured_data_for(operation_name, **options) ⇒ Object
Returns any data captured by operation_name.
If multiple instances of one operation class have modified the file, pass any options the specific instance of the operation was initialized with as the optional second argument.
39 40 41 42 43 44 |
# File 'lib/file_pipeline/versions/history.rb', line 39 def captured_data_for(operation_name, **) return if empty? captured_data.filter { |op, _| matches? op, operation_name, } .map(&:last) end |
#captured_data_with(tag) ⇒ Object
Returns an array with all data captured by operations with tag. Returns an empty array if there is no data for tag.
Tags are defined in FileOperations::CapturedDataTags
50 51 52 53 |
# File 'lib/file_pipeline/versions/history.rb', line 50 def captured_data_with(tag) captured_data.filter { |op, _| op.captured_data_tag == tag } .map(&:last) end |
#clear! ⇒ Object
Clears all history entries (version names and associated results).
56 57 58 |
# File 'lib/file_pipeline/versions/history.rb', line 56 def clear! @entries.clear end |
#empty? ⇒ Boolean
Returns true if self has no entries (version names and associated results), true otherwise.
62 63 64 |
# File 'lib/file_pipeline/versions/history.rb', line 62 def empty? @entries.empty? end |
#log ⇒ Object
Returns an array of triplets (arryas with three items each):
* Name of the file operation class (String).
* Options for the file operation instance (Hash).
* The log (Array).
70 71 72 |
# File 'lib/file_pipeline/versions/history.rb', line 70 def log filter(:log).map { |op, results| [op.name, op., results] } end |
#to_a ⇒ Object
Returns a two-dimensional Array where every nested Array will consist of the version name (file path) at index 0 and nil or an Array with all results objects for the version at index 1:
[version_name, [results1, ...]]
79 80 81 |
# File 'lib/file_pipeline/versions/history.rb', line 79 def to_a @entries.to_a end |
#versions ⇒ Object
Returns an array with paths to the version files of self (excluding #original).
85 86 87 |
# File 'lib/file_pipeline/versions/history.rb', line 85 def versions @entries.keys end |