timelines 0.1.3 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -0
- data/lib/generators/timelines/install/install_generator.rb +16 -0
- data/lib/generators/timelines/install/templates/create_timelines_events.rb +10 -0
- data/lib/timelines/{ephemeral.rb → models/concerns/ephemeral.rb} +5 -0
- data/lib/timelines/models/concerns/has_events.rb +11 -0
- data/lib/timelines/models/event.rb +8 -0
- data/lib/timelines/version.rb +1 -1
- data/lib/timelines.rb +3 -2
- metadata +8 -5
- data/lib/timelines/railtie.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9e0fcaa71f51ce05f909e1476d3697c19cbce690f581357a4dcc0507154456dd
|
4
|
+
data.tar.gz: 8d8f0580bd04c4dca4f7f64d17b889a68eb11d689f006d24aeff8364632aed28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80767881c109435b0f5b2e6c1da160f7cd57dd21d2c0b2ad0a0c6793beff2a930e11b2f159b0327ed813dd28435e461818cc533b5c8c244ead969b877d6c0f88
|
7
|
+
data.tar.gz: cbc54257925c045ea37ac59b85bd3f842060f6d28665cee5dd96a70a4b63affb6202a905c108cd74787186688e719a4abc64622998b3a739f850cf740a0a0417
|
data/README.md
CHANGED
@@ -13,6 +13,9 @@ This gives you the following Instance methods:
|
|
13
13
|
# Returns a boolean indicating whether the record is currently active
|
14
14
|
.active?
|
15
15
|
|
16
|
+
# Returns a boolean indicating whether the record was active at a given date
|
17
|
+
.active_at?(date)
|
18
|
+
|
16
19
|
# Sets the record's `started_at` to the current time to indicate that it has started
|
17
20
|
.start!
|
18
21
|
|
@@ -45,6 +48,14 @@ Add this line to your application's Gemfile:
|
|
45
48
|
gem "timelines"
|
46
49
|
```
|
47
50
|
|
51
|
+
## Migrations
|
52
|
+
Run this command to create a `timelines_events` table in your project:
|
53
|
+
```ruby
|
54
|
+
bin/rails generate timelines:install
|
55
|
+
```
|
56
|
+
|
57
|
+
Then you can call [whatever method] to get events attached to the record.
|
58
|
+
|
48
59
|
## Contributing
|
49
60
|
Pull requests/issues are welcome on GitHub
|
50
61
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Timelines
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < ::Rails::Generators::Base
|
4
|
+
source_root File.expand_path("templates", __dir__)
|
5
|
+
|
6
|
+
def copy_application_policy
|
7
|
+
[
|
8
|
+
"create_timelines_events.rb"
|
9
|
+
].each_with_index do |migration_file, index|
|
10
|
+
timestamp = (Time.current + index + 1).strftime("%Y%m%d%H%M%S")
|
11
|
+
template migration_file, "db/migrate/#{timestamp}_#{migration_file}.rb"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class CreateTimelinesEvents < ActiveRecord::Migration[7.1]
|
2
|
+
def change
|
3
|
+
create_table :timelines_events, id: :uuid do |t|
|
4
|
+
t.references :actor, type: :uuid, polymorphic: true
|
5
|
+
t.references :resource, type: :uuid, polymorphic: true
|
6
|
+
t.string :event
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -7,6 +7,7 @@ module Timelines
|
|
7
7
|
included do
|
8
8
|
scope :draft, -> { where(started_at: nil) }
|
9
9
|
scope :active, -> { where(ended_at: nil, started_at: [..Time.current]) }
|
10
|
+
scope :active_at, ->(date) { where("started_at <= ? AND (ended_at IS ? OR ended_at >= ?)", date, nil, date) }
|
10
11
|
scope :with_deleted, -> { unscope(where: :ended_at) }
|
11
12
|
scope :ended, -> { where.not(ended_at: nil) }
|
12
13
|
scope :deleted, -> { ended }
|
@@ -16,6 +17,10 @@ module Timelines
|
|
16
17
|
started? && !ended?
|
17
18
|
end
|
18
19
|
|
20
|
+
def active_at?(date)
|
21
|
+
self.class.active_at(date).where(id: id).exists?
|
22
|
+
end
|
23
|
+
|
19
24
|
def start!
|
20
25
|
return if started_at.present?
|
21
26
|
|
data/lib/timelines/version.rb
CHANGED
data/lib/timelines.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timelines
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Craig Gilchrist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -35,10 +35,13 @@ extra_rdoc_files: []
|
|
35
35
|
files:
|
36
36
|
- README.md
|
37
37
|
- Rakefile
|
38
|
+
- lib/generators/timelines/install/install_generator.rb
|
39
|
+
- lib/generators/timelines/install/templates/create_timelines_events.rb
|
38
40
|
- lib/tasks/timelines_tasks.rake
|
39
41
|
- lib/timelines.rb
|
40
|
-
- lib/timelines/ephemeral.rb
|
41
|
-
- lib/timelines/
|
42
|
+
- lib/timelines/models/concerns/ephemeral.rb
|
43
|
+
- lib/timelines/models/concerns/has_events.rb
|
44
|
+
- lib/timelines/models/event.rb
|
42
45
|
- lib/timelines/version.rb
|
43
46
|
homepage: https://github.com/Craggar/timelines
|
44
47
|
licenses:
|
@@ -62,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
62
65
|
- !ruby/object:Gem::Version
|
63
66
|
version: '0'
|
64
67
|
requirements: []
|
65
|
-
rubygems_version: 3.4
|
68
|
+
rubygems_version: 3.5.4
|
66
69
|
signing_key:
|
67
70
|
specification_version: 4
|
68
71
|
summary: Library for managing historical records.
|
data/lib/timelines/railtie.rb
DELETED