timelines 0.1.3 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b4ab605225ad136d4ab3388c6b450c3d5018b183eb254e94b06e15c7363b9bd
4
- data.tar.gz: 61b78dcb22d51581a05378b50dd4400afab543a22f25683204994f0f3907adbe
3
+ metadata.gz: 9e0fcaa71f51ce05f909e1476d3697c19cbce690f581357a4dcc0507154456dd
4
+ data.tar.gz: 8d8f0580bd04c4dca4f7f64d17b889a68eb11d689f006d24aeff8364632aed28
5
5
  SHA512:
6
- metadata.gz: c0c5fb0f0c4a5140afc3639b922d8adeec9bd4dc7ead6852c2a9a196586b00d43134cd86539d7a8aed485c2f30f02cd4b4bc7c848a868a6ed8526d72e2830127
7
- data.tar.gz: e0d32533e265a3e66203f5b84b81bb85f40f5b95dded491fa7743c2c0dc254beabb785548a1f59b5cc7fd5e429734bdb4b05753d870b96f6627b7cd8a8183abe
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
 
@@ -0,0 +1,11 @@
1
+ require "active_support/concern"
2
+
3
+ module Timelines
4
+ module HasEvents
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ has_many :events, class_name: "Timelines::Event", as: :resource, dependent: :destroy
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module Timelines
2
+ class Event < ActiveRecord::Base
3
+ self.table_name = "timelines_events"
4
+
5
+ belongs_to :actor, polymorphic: true
6
+ belongs_to :resource, polymorphic: true
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Timelines
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.3"
3
3
  end
data/lib/timelines.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "timelines/version"
2
- require "timelines/railtie"
3
- require "timelines/ephemeral"
2
+ require "timelines/models/concerns/ephemeral"
3
+ require "timelines/models/concerns/has_events"
4
+ require "timelines/models/event"
4
5
 
5
6
  module Timelines
6
7
  end
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.1.3
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: 2023-10-09 00:00:00.000000000 Z
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/railtie.rb
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.10
68
+ rubygems_version: 3.5.4
66
69
  signing_key:
67
70
  specification_version: 4
68
71
  summary: Library for managing historical records.
@@ -1,4 +0,0 @@
1
- module Timelines
2
- class Railtie < ::Rails::Railtie
3
- end
4
- end