fast_versioning 0.4.1 → 0.7.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: 23f653a3f9017175d02635e4631b112c39f4c172d574ff773c28fddb8779819c
4
- data.tar.gz: 05e54ed2435fb1590af1013445a151d60aed19bd86d24c35339a5bba8ee4bdda
3
+ metadata.gz: b1f61010645683fd0891a8cd04d683760f1dd8693a69a216cfe3d3b914e57dac
4
+ data.tar.gz: ab643c5cda9cef86f684e54f4fa83098cf9ee4947419938ca0dfbd0fa3c21673
5
5
  SHA512:
6
- metadata.gz: dc289843b4225045ba104c24f887b4da440e86b22ee58df62ee323c0e89e908999cd8555bfd94cddda0608e010dff2f8af827e45d6cf4d613604a99fcdd3f36b
7
- data.tar.gz: 0c4a213dbd1ab861ce77cd0a1a04dca9c5166f693f1296c585655e622b1e535590b825f0393742ff9b42a92adc8262f69d45a41f56ad6c9b97ac4eacfd1cd06c
6
+ metadata.gz: a41e86ce08b616ccdc27059a328b99e5a724422fb2d05edae66d0462ae85b2db95fbb27800e3a5243a312e0f42d9623812e54b15f191cc4e32e3068c300d2ff0
7
+ data.tar.gz: d3b79718003b4fc2729730d3d7274aca7c9374111d71b23bf506e4a1e5cf2ef9e71b5d21edafe670e2f5e0d64b87e1260512d76c5b9ba7b497bd79cf6de29599
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
@@ -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
@@ -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'
metadata CHANGED
@@ -1,31 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_versioning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.7.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: 2019-09-10 00:00:00.000000000 Z
11
+ date: 2022-03-28 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
14
  name: rails
17
15
  requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - "~>"
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '5.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.2'
22
23
  type: :runtime
23
24
  prerelease: false
24
25
  version_requirements: !ruby/object:Gem::Requirement
25
26
  requirements:
26
- - - "~>"
27
+ - - ">="
27
28
  - !ruby/object:Gem::Version
28
29
  version: '5.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.2'
29
33
  - !ruby/object:Gem::Dependency
30
34
  name: paper_trail
31
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,16 +48,16 @@ dependencies:
44
48
  name: sqlite3
45
49
  requirement: !ruby/object:Gem::Requirement
46
50
  requirements:
47
- - - "~>"
51
+ - - ">="
48
52
  - !ruby/object:Gem::Version
49
- version: 1.3.13
53
+ version: '0'
50
54
  type: :development
51
55
  prerelease: false
52
56
  version_requirements: !ruby/object:Gem::Requirement
53
57
  requirements:
54
- - - "~>"
58
+ - - ">="
55
59
  - !ruby/object:Gem::Version
56
- version: 1.3.13
60
+ version: '0'
57
61
  - !ruby/object:Gem::Dependency
58
62
  name: rspec-rails
59
63
  requirement: !ruby/object:Gem::Requirement
@@ -82,9 +86,23 @@ dependencies:
82
86
  - - ">="
83
87
  - !ruby/object:Gem::Version
84
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'
85
103
  description: Fast versioning extension for paper_trail
86
104
  email:
87
- - engineering@arcadiapower.com
105
+ - engineering@arcadia.com
88
106
  executables: []
89
107
  extensions: []
90
108
  extra_rdoc_files: []
@@ -99,13 +117,15 @@ files:
99
117
  - lib/fast_versioning/fast_versioned.rb
100
118
  - lib/fast_versioning/paper_trail_extensions.rb
101
119
  - lib/fast_versioning/railtie.rb
120
+ - lib/fast_versioning/timeline.rb
121
+ - lib/fast_versioning/timelines/duration.rb
102
122
  - lib/fast_versioning/tracked_attribute.rb
103
123
  - lib/fast_versioning/value_change.rb
104
124
  homepage: https://github.com/ArcadiaPower/fast-versioning
105
125
  licenses:
106
126
  - MIT
107
127
  metadata: {}
108
- post_install_message:
128
+ post_install_message:
109
129
  rdoc_options: []
110
130
  require_paths:
111
131
  - lib
@@ -120,8 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
140
  - !ruby/object:Gem::Version
121
141
  version: '0'
122
142
  requirements: []
123
- rubygems_version: 3.0.3
124
- signing_key:
143
+ rubygems_version: 3.2.9
144
+ signing_key:
125
145
  specification_version: 4
126
146
  summary: Fast versioning extension for paper_trail
127
147
  test_files: []