on_cue 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1648e82254d646c689553b1d5dcf844c11c1b2695ac32bf14905495a89292afb
4
+ data.tar.gz: 811c712e973cdd3b005b0ca39eaf30fe055894694f4a6d07f01f179382a31633
5
+ SHA512:
6
+ metadata.gz: 71abdca2f51889c7f401ab7b1a5900492d3d091ae9719319369952f0cca21184ebcc20ab10acf74b81ed71fac877769f66636d6512da6ade61f066975c67864a
7
+ data.tar.gz: 27dae00b75c83da7b0ffccb36a8be091d3ff75c9f293a3a9d28d7060f6d166a4891cffcbc7f893a782c533e94680d08677f8f71fe1fa0edc29670b4f030490c2
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2026 Tyler Schneider
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # on_cue
2
+
3
+ A Rails engine that stores an item for a record at a time, and calls the handler the host app registered for it once that time has passed.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem "on_cue"
9
+ ```
10
+
11
+ Create the items table:
12
+
13
+ ```sh
14
+ bin/rails generate on_cue:install
15
+ bin/rails db:migrate
16
+ ```
17
+
18
+ Set up on_cue in an initializer:
19
+
20
+ ```ruby
21
+ OnCue.configure do |config|
22
+ config.register_handler(:renewal_reminder, "RenewalReminder")
23
+ config.time_zone = "America/Chicago"
24
+ config.current_account_method = :current_account
25
+ end
26
+ ```
27
+
28
+ A handler is a class named by a string. Each due item gets a new instance of it, and its `call` method is given the item. What it returns is stored on the item as its result.
29
+
30
+ Run `OnCue::DueJob` on a recurring schedule in the host app, such as every minute in `config/recurring.yml` with Solid Queue:
31
+
32
+ ```yaml
33
+ on_cue_due:
34
+ class: OnCue::DueJob
35
+ schedule: every minute
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```ruby
41
+ OnCue.schedule(contract, at: contract.ends_on, handler: :renewal_reminder, account: contract.account)
42
+ ```
43
+
44
+ `at:` takes a time, or a date meaning the start of that day in the business time zone. Each run of `OnCue::DueJob` calls the named handler once for every item whose time has passed and that has not fired, then records when it fired.
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/setup"
2
+
3
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
4
+ load "rails/tasks/engine.rake"
5
+
6
+ require "bundler/gem_tasks"
7
+ require "rake/testtask"
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << "test"
11
+ t.libs << "lib"
12
+ t.test_files = FileList["test/**/*_test.rb"]
13
+ end
14
+
15
+ task default: :test
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module OnCue
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module OnCue
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module OnCue
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ module OnCue
2
+ class DueJob < ApplicationJob
3
+ def perform
4
+ Item.where(fired_at: nil, due_at: ..Time.current).find_each do |item|
5
+ result = OnCue.configuration.handler(item.handler).new.call(item)
6
+ item.update!(fired_at: Time.current, result: result)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module OnCue
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module OnCue
2
+ class Item < ApplicationRecord
3
+ belongs_to :account, polymorphic: true
4
+ belongs_to :record, polymorphic: true
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>On cue</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= yield :head %>
9
+
10
+ <%= stylesheet_link_tag "on_cue/application", media: "all" %>
11
+ </head>
12
+ <body>
13
+
14
+ <%= yield %>
15
+
16
+ </body>
17
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ OnCue::Engine.routes.draw do
2
+ end
@@ -0,0 +1,18 @@
1
+ require "rails/generators"
2
+ require "rails/generators/active_record"
3
+
4
+ module OnCue
5
+ module Generators
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include ActiveRecord::Generators::Migration
8
+
9
+ source_root File.expand_path("templates", __dir__)
10
+
11
+ desc "Installs OnCue: copies the migration that creates its items table."
12
+
13
+ def copy_migration
14
+ migration_template "create_on_cue_items.rb.erb", "db/migrate/create_on_cue_items.rb"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ class CreateOnCueItems < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
2
+ def change
3
+ create_table :on_cue_items do |t|
4
+ t.references :account, polymorphic: true, null: false
5
+ t.references :record, polymorphic: true, null: false
6
+ t.string :handler, null: false
7
+ t.datetime :due_at, null: false
8
+ t.datetime :fired_at
9
+ t.json :result
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ require "active_support/core_ext/string/inflections"
2
+
3
+ module OnCue
4
+ class Configuration
5
+ attr_accessor :time_zone, :current_account_method
6
+
7
+ def initialize
8
+ @handlers = {}
9
+ end
10
+
11
+ def register_handler(name, handler)
12
+ @handlers[name.to_s] = handler.to_s
13
+ end
14
+
15
+ def handler(name)
16
+ @handlers.fetch(name.to_s).constantize
17
+ end
18
+ end
19
+
20
+ def self.configuration
21
+ @configuration ||= Configuration.new
22
+ end
23
+
24
+ def self.configure
25
+ yield(configuration)
26
+ end
27
+
28
+ def self.reset_configuration!
29
+ @configuration = Configuration.new
30
+ end
31
+ end
@@ -0,0 +1,5 @@
1
+ module OnCue
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace OnCue
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module OnCue
2
+ VERSION = "0.1.0"
3
+ end
data/lib/on_cue.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "on_cue/version"
2
+ require "on_cue/configuration"
3
+ require "on_cue/engine"
4
+
5
+ module OnCue
6
+ def self.schedule(record, at:, handler:, account:)
7
+ Item.create!(record: record, account: account, handler: handler.to_s, due_at: due_at(at))
8
+ end
9
+
10
+ def self.due_at(at)
11
+ at.is_a?(Date) ? at.in_time_zone(configuration.time_zone) : at
12
+ end
13
+ private_class_method :due_at
14
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :on_cue do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: on_cue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Schneider
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-12-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '7.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '7.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '7.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '7.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activejob
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '7.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '7.0'
55
+ description: A Rails engine that stores an item for a record at a time and calls the
56
+ handler the host app registered for it once that time has passed.
57
+ email:
58
+ - tylercschneider@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - MIT-LICENSE
64
+ - README.md
65
+ - Rakefile
66
+ - app/assets/stylesheets/on_cue/application.css
67
+ - app/controllers/on_cue/application_controller.rb
68
+ - app/helpers/on_cue/application_helper.rb
69
+ - app/jobs/on_cue/application_job.rb
70
+ - app/jobs/on_cue/due_job.rb
71
+ - app/models/on_cue/application_record.rb
72
+ - app/models/on_cue/item.rb
73
+ - app/views/layouts/on_cue/application.html.erb
74
+ - config/routes.rb
75
+ - lib/generators/on_cue/install/install_generator.rb
76
+ - lib/generators/on_cue/install/templates/create_on_cue_items.rb.erb
77
+ - lib/on_cue.rb
78
+ - lib/on_cue/configuration.rb
79
+ - lib/on_cue/engine.rb
80
+ - lib/on_cue/version.rb
81
+ - lib/tasks/on_cue_tasks.rake
82
+ homepage: https://github.com/DYB-Development/on_cue
83
+ licenses:
84
+ - MIT
85
+ metadata:
86
+ homepage_uri: https://github.com/DYB-Development/on_cue
87
+ source_code_uri: https://github.com/DYB-Development/on_cue
88
+ changelog_uri: https://github.com/DYB-Development/on_cue/blob/main/CHANGELOG.md
89
+ bug_tracker_uri: https://github.com/DYB-Development/on_cue/issues
90
+ rubygems_mfa_required: 'true'
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 3.2.0
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 3.5.16
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Dated items for Rails apps, each fired once at its time.
110
+ test_files: []