fast_versioning 0.2.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: 87613fb753cc329fe499c239bc0a84ce505879abb87c4c74cff07c657b0b86db
4
- data.tar.gz: 7dec724f5f187384c874ff7af8bd4751054d5462e0e2233d94dfc03075f5e3f7
3
+ metadata.gz: 2bd60ff0e35e539783059550b97c8075a76422d3a2ed83f025a9633e5c5396ec
4
+ data.tar.gz: d5ec4ba1e53650f50edb668abb3e4f77f9275984f7b051708401ed92c6469630
5
5
  SHA512:
6
- metadata.gz: 9b635ba136aed6ec8b8ef573a4e8d958826ff5d481a83fc75f1dddee18d706b6b8909a3b323d1e3db18bf6042f7e4cda7c03ad770848a22147ee19a7e982f8b1
7
- data.tar.gz: 8a2ca6a9207836d1f54feaa6ffddfd86a3583493b00aad0897eb3a25f321e47752892f84b68e7298e96247d944b6c389f1c4742ce04fe4ef2b530b511f143f88
6
+ metadata.gz: 6ae2748e70169334cd3d1920fa13ea740bdcb6310dd4d656d1b188b96a2bfb3ce029551b229cff7a1080295c5884827ecee9c6ea8bd8b29593ed8b04b445d0e9
7
+ data.tar.gz: 57b5ba1b6e5444dd4aa2caf694a89fabe7cbc9a4268e974a8d664f3075e37e507a81b1f1d1d5156f24da28da9eb99fa89b0a3d03db698716c23ef43d8986a7ee
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/ArcadiaPower/fast-versioning.svg?branch=master)](https://travis-ci.org/ArcadiaPower/fast-versioning)
2
+
1
3
  Fast Versioning
2
4
  ===========
3
5
  A [PaperTrail](https://github.com/airblade/paper_trail) extension for seamless fast key/value versioning of individual object attributes, which can be queried.
@@ -83,6 +85,38 @@ Example usage:
83
85
 
84
86
  # query
85
87
  your_model.fast_versions_for(:status).where(value: 'active').where(prev_value: 'incomplete')
88
+
89
+ # alternatively:
90
+ FastVersioning::FastVersion.find_by(
91
+ item_type: 'ItemType',
92
+ name: 'name',
93
+ value: 'value'
94
+ prev_value: 'prev_value'
95
+ )
96
+ ```
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
+
115
+ Testing
116
+ -------------
117
+ ```
118
+ bundle exec appraisal install
119
+ bundle exec appraisal rspec
86
120
  ```
87
121
 
88
- An [Arcadia Power](http://www.arcadiapower.com) Project
122
+ An [Arcadia](http://www.arcadia.com) Project
@@ -1,11 +1,9 @@
1
1
  module FastVersioning
2
2
  class FastVersion < ActiveRecord::Base
3
3
  belongs_to :item, polymorphic: true
4
- belongs_to :whodunnit, polymorphic: true
4
+ belongs_to :whodunnit, polymorphic: true, optional: true
5
5
  belongs_to :version, class_name: 'PaperTrail::Version'
6
6
 
7
- validates :version_id, uniqueness: { scope: :name }
8
-
9
7
  serialize :meta, JSON
10
8
  end
11
9
  end
@@ -0,0 +1,5 @@
1
+ class AddUniqueIndexToVersionIdName < ActiveRecord::Migration[5.0]
2
+ def change
3
+ add_index :fast_versioning_fast_versions, %i[version_id name], unique: true
4
+ end
5
+ 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'
@@ -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.2.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: 2019-01-30 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
@@ -21,7 +19,7 @@ dependencies:
21
19
  version: '5.0'
22
20
  - - "<"
23
21
  - !ruby/object:Gem::Version
24
- version: '5.2'
22
+ version: '6.1'
25
23
  type: :runtime
26
24
  prerelease: false
27
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -31,7 +29,7 @@ dependencies:
31
29
  version: '5.0'
32
30
  - - "<"
33
31
  - !ruby/object:Gem::Version
34
- version: '5.2'
32
+ version: '6.1'
35
33
  - !ruby/object:Gem::Dependency
36
34
  name: paper_trail
37
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,9 +37,6 @@ dependencies:
39
37
  - - ">="
40
38
  - !ruby/object:Gem::Version
41
39
  version: '4.2'
42
- - - "<"
43
- - !ruby/object:Gem::Version
44
- version: '6'
45
40
  type: :runtime
46
41
  prerelease: false
47
42
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,9 +44,6 @@ dependencies:
49
44
  - - ">="
50
45
  - !ruby/object:Gem::Version
51
46
  version: '4.2'
52
- - - "<"
53
- - !ruby/object:Gem::Version
54
- version: '6'
55
47
  - !ruby/object:Gem::Dependency
56
48
  name: sqlite3
57
49
  requirement: !ruby/object:Gem::Requirement
@@ -80,9 +72,37 @@ dependencies:
80
72
  - - ">="
81
73
  - !ruby/object:Gem::Version
82
74
  version: '0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: appraisal
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
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'
83
103
  description: Fast versioning extension for paper_trail
84
104
  email:
85
- - engineering@arcadiapower.com
105
+ - engineering@arcadia.com
86
106
  executables: []
87
107
  extensions: []
88
108
  extra_rdoc_files: []
@@ -91,18 +111,21 @@ files:
91
111
  - Rakefile
92
112
  - app/models/fast_versioning/fast_version.rb
93
113
  - db/migrate/20160914161314_create_fast_versioning_fast_versions.rb
114
+ - db/migrate/20190514134359_add_unique_index_to_version_id_name.rb
94
115
  - lib/fast_versioning.rb
95
116
  - lib/fast_versioning/engine.rb
96
117
  - lib/fast_versioning/fast_versioned.rb
97
118
  - lib/fast_versioning/paper_trail_extensions.rb
98
119
  - lib/fast_versioning/railtie.rb
120
+ - lib/fast_versioning/timeline.rb
121
+ - lib/fast_versioning/timelines/duration.rb
99
122
  - lib/fast_versioning/tracked_attribute.rb
100
123
  - lib/fast_versioning/value_change.rb
101
124
  homepage: https://github.com/ArcadiaPower/fast-versioning
102
125
  licenses:
103
126
  - MIT
104
127
  metadata: {}
105
- post_install_message:
128
+ post_install_message:
106
129
  rdoc_options: []
107
130
  require_paths:
108
131
  - lib
@@ -117,8 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
140
  - !ruby/object:Gem::Version
118
141
  version: '0'
119
142
  requirements: []
120
- rubygems_version: 3.0.2
121
- signing_key:
143
+ rubygems_version: 3.1.2
144
+ signing_key:
122
145
  specification_version: 4
123
146
  summary: Fast versioning extension for paper_trail
124
147
  test_files: []