fast_versioning 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b964a2fa26408fcc41f0a70ccbed7cf48b26e8ad1e0cc997abccd62a81d56565
4
- data.tar.gz: 6cb92fbca8479834a2cc146c2e73abb4a47c6c7843a2a72f428c2ff516300d75
3
+ metadata.gz: 2bd60ff0e35e539783059550b97c8075a76422d3a2ed83f025a9633e5c5396ec
4
+ data.tar.gz: d5ec4ba1e53650f50edb668abb3e4f77f9275984f7b051708401ed92c6469630
5
5
  SHA512:
6
- metadata.gz: 6cec867522c2a081a4399714a2d9126ba6994661348a83be153edd681cf640ea94301b870af14d35ef0b429c2083ca31f8bb7cb8446bf7581b04c471ef639bfe
7
- data.tar.gz: a03dd2e567088081d9e2752f54e16f705a476d55852197c4e70ab1dac0a7acff758cc231d97928620267ff630ef9dcbbe161b56969a7fd714044491b83d0e532
6
+ metadata.gz: 6ae2748e70169334cd3d1920fa13ea740bdcb6310dd4d656d1b188b96a2bfb3ce029551b229cff7a1080295c5884827ecee9c6ea8bd8b29593ed8b04b445d0e9
7
+ data.tar.gz: 57b5ba1b6e5444dd4aa2caf694a89fabe7cbc9a4268e974a8d664f3075e37e507a81b1f1d1d5156f24da28da9eb99fa89b0a3d03db698716c23ef43d8986a7ee
data/README.md CHANGED
@@ -95,6 +95,23 @@ Example usage:
95
95
  )
96
96
  ```
97
97
 
98
+ ### Timeline helper
99
+ `FastVersioning::Timeline` is a simple helper you can use to generate a timeline hash for a tracked property
100
+
101
+ example usage:
102
+ ```ruby
103
+ FastVersioning::Timeline.new(
104
+ fast_versions: model.fast_versions,
105
+ name: "status"
106
+ ).to_h
107
+
108
+ # {
109
+ # Thu, 01 Apr 2021 14:08:48 EDT -04:00..Mon, 05 Apr 2021 21:53:48 EDT -04:00 => 'active',
110
+ # Mon, 05 Apr 2021 21:53:48 EDT -04:00..Mon, 05 Apr 2021 22:02:44 EDT -04:00 => 'inactive',
111
+ # Mon, 05 Apr 2021 22:02:44 EDT -04:00..Infinity => 'active'
112
+ # }
113
+ ```
114
+
98
115
  Testing
99
116
  -------------
100
117
  ```
@@ -102,4 +119,4 @@ bundle exec appraisal install
102
119
  bundle exec appraisal rspec
103
120
  ```
104
121
 
105
- An [Arcadia Power](http://www.arcadiapower.com) Project
122
+ An [Arcadia](http://www.arcadia.com) Project
@@ -2,6 +2,8 @@ require 'paper_trail'
2
2
  require 'fast_versioning/tracked_attribute'
3
3
  require 'fast_versioning/fast_versioned'
4
4
  require 'fast_versioning/value_change'
5
+ require 'fast_versioning/timelines/duration'
6
+ require 'fast_versioning/timeline'
5
7
  require 'fast_versioning/paper_trail_extensions'
6
8
  require 'fast_versioning/railtie'
7
9
  require 'fast_versioning/engine'
@@ -0,0 +1,47 @@
1
+ module FastVersioning
2
+ # a timeline for a tracked property
3
+ class Timeline
4
+ # @param name [String] tracked property name
5
+ # @param fast_versions [ActiveRecord::Collection] FastVersion collection
6
+ #
7
+ def initialize(fast_versions:, name:)
8
+ self.fast_versions = fast_versions
9
+ self.name = name
10
+ end
11
+
12
+ # @return [Hash] hash of duration => date ranges
13
+ #
14
+ # @example
15
+ #
16
+ # FastVersioning::Timeline.new(fast_versions: model.fast_versions, name: 'status').to_h
17
+ #
18
+ # {
19
+ # Thu, 01 Apr 2021 14:08:48 EDT -04:00..Mon, 05 Apr 2021 21:53:48 EDT -04:00 => 'active',
20
+ # Mon, 05 Apr 2021 21:53:48 EDT -04:00..Mon, 05 Apr 2021 22:02:44 EDT -04:00 => 'inactive'
21
+ # }
22
+ #
23
+ def to_h
24
+ durations_array.map do |duration|
25
+ [duration.date_range, duration.value]
26
+ end.to_h
27
+ end
28
+
29
+ private
30
+
31
+ attr_accessor :fast_versions, :name
32
+
33
+ def filtered_fast_versions
34
+ fast_versions.where(name: name).order('created_at')
35
+ end
36
+
37
+ def durations_array
38
+ @value_durations ||= (filtered_fast_versions.to_a + [nil]).each_cons(2).map do |item, prev_item|
39
+ Timelines::Duration.new(
40
+ value: item.value,
41
+ start_date: item.created_at,
42
+ end_date: prev_item&.created_at
43
+ )
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,32 @@
1
+ module FastVersioning
2
+ # value duration period
3
+ # @private
4
+ module Timelines
5
+ class Duration
6
+ # @param value [String] tracked property name
7
+ # @param start_date [Time] when was the value set
8
+ # @param end_date [Time, nil] when was the value unset (nil will default to Float::INFINITY)
9
+ def initialize(value:, start_date:, end_date:)
10
+ self.value = value
11
+ self.start_date = start_date
12
+ self.end_date = end_date
13
+ end
14
+
15
+ # @return [Range]
16
+ def date_range
17
+ start_date..end_date_or_the_future
18
+ end
19
+
20
+ attr_reader :value
21
+
22
+ private
23
+
24
+ attr_accessor :start_date, :end_date
25
+ attr_writer :value
26
+
27
+ def end_date_or_the_future
28
+ end_date || Float::INFINITY
29
+ end
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,16 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_versioning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
- - Arcadia Power
8
- - Iwo Dziechciarow
9
- - Justin Doody
10
- autorequire:
7
+ - Arcadia
8
+ autorequire:
11
9
  bindir: bin
12
10
  cert_chain: []
13
- date: 2020-01-13 00:00:00.000000000 Z
11
+ date: 2021-05-04 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
14
  name: rails
@@ -88,9 +86,23 @@ dependencies:
88
86
  - - ">="
89
87
  - !ruby/object:Gem::Version
90
88
  version: '0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: timecop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
91
103
  description: Fast versioning extension for paper_trail
92
104
  email:
93
- - engineering@arcadiapower.com
105
+ - engineering@arcadia.com
94
106
  executables: []
95
107
  extensions: []
96
108
  extra_rdoc_files: []
@@ -105,13 +117,15 @@ files:
105
117
  - lib/fast_versioning/fast_versioned.rb
106
118
  - lib/fast_versioning/paper_trail_extensions.rb
107
119
  - lib/fast_versioning/railtie.rb
120
+ - lib/fast_versioning/timeline.rb
121
+ - lib/fast_versioning/timelines/duration.rb
108
122
  - lib/fast_versioning/tracked_attribute.rb
109
123
  - lib/fast_versioning/value_change.rb
110
124
  homepage: https://github.com/ArcadiaPower/fast-versioning
111
125
  licenses:
112
126
  - MIT
113
127
  metadata: {}
114
- post_install_message:
128
+ post_install_message:
115
129
  rdoc_options: []
116
130
  require_paths:
117
131
  - lib
@@ -126,8 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
140
  - !ruby/object:Gem::Version
127
141
  version: '0'
128
142
  requirements: []
129
- rubygems_version: 3.1.1
130
- signing_key:
143
+ rubygems_version: 3.1.2
144
+ signing_key:
131
145
  specification_version: 4
132
146
  summary: Fast versioning extension for paper_trail
133
147
  test_files: []