periodic_records 0.3.1 → 0.5.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
- SHA1:
3
- metadata.gz: ae65d46b1c1fd12132918c0d227aab03751ecc0c
4
- data.tar.gz: ef78b4a608ea9a0edfa3f88d395bc3cce285f201
2
+ SHA256:
3
+ metadata.gz: a9522120598a9705373b87049241d923f9e7dc26986f91a3bef02c62d6cfcf40
4
+ data.tar.gz: e8e8e1b941168c2f4d04d168ff2e3d61de09c5a6079ae6b26eda04e175bf8ddd
5
5
  SHA512:
6
- metadata.gz: 42d890582bd6aa6ce911924cad8251dfce77ce779cf0673f370ab69de58c5d104a99e6cfae55caaa3c553b5528832c8e8eebc3304d6f7486edc03f8b2b46cd0f
7
- data.tar.gz: 3fd57d7ce979172a948a1b9e32a04871f6bb58e677f3f777a831c3e8a365793f458b7fdca823c4723079ee29931e749289cc1b55d78dac85abca5dfaacd02570
6
+ metadata.gz: 75f947303334f4cb0208933e1e7885717aca477566c5763ecb49806f2137ddbd303af30076d655435fd9c3422d3e75335e21f3bc29952952188ef01a81a813a0
7
+ data.tar.gz: 602eedb548e740e685a592aa79b5b4bbc236dce4ed5391f11183ae7dcaa60a5010017b3cb32ffce62fd76c8b28736d2cb3f0f6604f7fcc779d5c57c802095b37
@@ -0,0 +1,23 @@
1
+ name: Ruby
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby-version: ["3.1", "3.2", "3.3"]
11
+ rails-version: ["6.1.0", "7.0.0", "7.1.0"]
12
+ env:
13
+ RAILS_VERSION: ${{ matrix.rails-version }}
14
+
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby-version }}
21
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
22
+ - name: Run tests
23
+ run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [0.5.0] - 2024-02-21
7
+
8
+ - Support rails 7 #6
9
+
10
+ ## [0.4.0] - 2019-04-02
11
+
12
+ - Add time sensitive period splitting #4
13
+
6
14
  ## [0.3.1] - 2018-05-24
7
15
 
8
16
  - Allow to add custom duplication logic #3
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # PeriodicRecords
2
2
 
3
- [![Build Status](https://travis-ci.org/mak-it/periodic_records.svg?branch=master)](https://travis-ci.org/mak-it/periodic_records)
4
-
5
3
  Support functions for ActiveRecord models with periodic entries.
6
4
 
7
5
  * Supports periods where the smallest unit is a whole day
@@ -102,7 +100,7 @@ employee.employee_assignments.within_date(Date.tomorrow)
102
100
  ```
103
101
 
104
102
  ```ruby
105
- employee.employee_assignments.within_interval(Date.current.beginning_of_month...Date.current.end_of_month)
103
+ employee.employee_assignments.within_interval(Date.current.beginning_of_month, Date.current.end_of_month)
106
104
  ```
107
105
 
108
106
  Look up records starting with specific date with `from_date`
@@ -151,6 +149,12 @@ class AddEmployeeAssignmentsOverlappingDatesConstraint < ActiveRecord::Migration
151
149
  end
152
150
  ```
153
151
 
152
+ ## Time sensitive records
153
+
154
+ If you need your records to be split with time component, then set `start_at` and `end_at` columns to `datetime` type.
155
+
156
+ Use `TSRANGE` instead of `DATERANGE` when creating database constraint.
157
+
154
158
  ## Gapless records
155
159
 
156
160
  If you want to avoid gaps between records, you can include also `PeriodicRecords::Gapless`.
@@ -30,8 +30,15 @@ module PeriodicRecords
30
30
  state.send("#{reflection.inverse_of.name}=", record)
31
31
  end
32
32
  unless associations.empty?
33
- ActiveRecord::Associations::Preloader.new.
34
- preload(states, associations)
33
+ if ActiveRecord::VERSION::MAJOR >= 7
34
+ ActiveRecord::Associations::Preloader.new(
35
+ records: states,
36
+ associations: associations
37
+ ).call
38
+ else
39
+ ActiveRecord::Associations::Preloader.new.
40
+ preload(states, associations)
41
+ end
35
42
  end
36
43
  end
37
44
  end
@@ -76,6 +76,18 @@ module PeriodicRecords
76
76
  dup
77
77
  end
78
78
 
79
+ def record_split_step
80
+ @record_split_step ||= begin
81
+ column = self.class.column_for_attribute(:start_at)
82
+ if column.type == :datetime
83
+ precision = column.precision || 6
84
+ Float("1.0e-#{precision}").seconds
85
+ else
86
+ 1.day
87
+ end
88
+ end
89
+ end
90
+
79
91
  private
80
92
 
81
93
  def set_default_period
@@ -89,23 +101,23 @@ module PeriodicRecords
89
101
 
90
102
  def split_overlapping_record(overlapping_record)
91
103
  overlapping_record_end = overlapping_record.periodic_dup
92
- overlapping_record_end.start_at = end_at + 1.day
104
+ overlapping_record_end.start_at = end_at + record_split_step
93
105
  overlapping_record_end.end_at = overlapping_record.end_at
94
106
 
95
107
  overlapping_record_start = overlapping_record
96
- overlapping_record_start.end_at = start_at - 1.day
108
+ overlapping_record_start.end_at = start_at - record_split_step
97
109
 
98
110
  overlapping_record_start.save(validate: false)
99
111
  overlapping_record_end.save(validate: false)
100
112
  end
101
113
 
102
114
  def adjust_overlapping_record_end_at(overlapping_record)
103
- overlapping_record.end_at = start_at - 1.day
115
+ overlapping_record.end_at = start_at - record_split_step
104
116
  overlapping_record.save(validate: false)
105
117
  end
106
118
 
107
119
  def adjust_overlapping_record_start_at(overlapping_record)
108
- overlapping_record.start_at = end_at + 1.day
120
+ overlapping_record.start_at = end_at + record_split_step
109
121
  overlapping_record.save(validate: false)
110
122
  end
111
123
 
@@ -1,3 +1,3 @@
1
1
  module PeriodicRecords
2
- VERSION = "0.3.1"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "periodic_records"
8
8
  spec.version = PeriodicRecords::VERSION
9
9
  spec.authors = ["Edgars Beigarts", "Toms Mikoss"]
10
- spec.email = ["edgars.beigarts@makit.lv", "toms.mikoss@makit.lv"]
10
+ spec.email = ["edgars.beigarts@mitigate.dev", "toms.mikoss@mitigate.dev"]
11
11
 
12
12
  spec.summary = %q{Support functions for ActiveRecord models with periodic entries}
13
13
  spec.description = %q{Support functions for ActiveRecord models with periodic entries}
@@ -19,11 +19,13 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_runtime_dependency "activerecord", ">= 5.1"
23
- spec.add_runtime_dependency "activesupport", ">= 5.1"
22
+ spec.required_ruby_version = '>= 3.1.0'
24
23
 
25
- spec.add_development_dependency "bundler", "~> 1.9"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "rspec", "~> 3.3"
24
+ spec.add_runtime_dependency "activerecord", ">= 6.1"
25
+ spec.add_runtime_dependency "activesupport", ">= 6.1"
26
+
27
+ spec.add_development_dependency "bundler", ">= 1.9"
28
+ spec.add_development_dependency "rake", "~> 13.1"
29
+ spec.add_development_dependency "rspec", "~> 3.13"
28
30
  spec.add_development_dependency "sqlite3"
29
31
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: periodic_records
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edgars Beigarts
8
8
  - Toms Mikoss
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-05-24 00:00:00.000000000 Z
12
+ date: 2024-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -17,40 +17,40 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '5.1'
20
+ version: '6.1'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '5.1'
27
+ version: '6.1'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: activesupport
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '5.1'
34
+ version: '6.1'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '5.1'
41
+ version: '6.1'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: bundler
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '1.9'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '1.9'
56
56
  - !ruby/object:Gem::Dependency
@@ -59,28 +59,28 @@ dependencies:
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '10.0'
62
+ version: '13.1'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '10.0'
69
+ version: '13.1'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rspec
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - "~>"
75
75
  - !ruby/object:Gem::Version
76
- version: '3.3'
76
+ version: '3.13'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: '3.3'
83
+ version: '3.13'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: sqlite3
86
86
  requirement: !ruby/object:Gem::Requirement
@@ -97,15 +97,15 @@ dependencies:
97
97
  version: '0'
98
98
  description: Support functions for ActiveRecord models with periodic entries
99
99
  email:
100
- - edgars.beigarts@makit.lv
101
- - toms.mikoss@makit.lv
100
+ - edgars.beigarts@mitigate.dev
101
+ - toms.mikoss@mitigate.dev
102
102
  executables: []
103
103
  extensions: []
104
104
  extra_rdoc_files: []
105
105
  files:
106
+ - ".github/workflows/ruby.yml"
106
107
  - ".gitignore"
107
108
  - ".rspec"
108
- - ".travis.yml"
109
109
  - CHANGELOG.md
110
110
  - Gemfile
111
111
  - LICENSE.txt
@@ -123,7 +123,7 @@ homepage: https://github.com/mak-it/periodic_records
123
123
  licenses:
124
124
  - MIT
125
125
  metadata: {}
126
- post_install_message:
126
+ post_install_message:
127
127
  rdoc_options: []
128
128
  require_paths:
129
129
  - lib
@@ -131,16 +131,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
131
  requirements:
132
132
  - - ">="
133
133
  - !ruby/object:Gem::Version
134
- version: '0'
134
+ version: 3.1.0
135
135
  required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - ">="
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  requirements: []
141
- rubyforge_project:
142
- rubygems_version: 2.6.10
143
- signing_key:
141
+ rubygems_version: 3.3.26
142
+ signing_key:
144
143
  specification_version: 4
145
144
  summary: Support functions for ActiveRecord models with periodic entries
146
145
  test_files: []
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2
4
- - 2.3
5
- - 2.4
6
- - 2.5
7
- env:
8
- - "RAILS_VERSION=5.1.0"
9
- - "RAILS_VERSION=5.2.0.beta2"