dials 0.1.0 → 0.2.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 +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/dials/active_record/models.rb +5 -1
- data/lib/dials/config.rb +26 -0
- data/lib/dials/version.rb +1 -1
- data/lib/generators/dials/install/install_generator.rb +14 -3
- data/lib/generators/dials/install/templates/initializer.rb.tt +12 -1
- data/lib/generators/dials/install/templates/migration.rb.tt +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8ecb8e740f9cf1218279b9936a938830e4bc8c34b34b6b9da0861a9d10f4d504
|
|
4
|
+
data.tar.gz: bcd05bebf177970aedcf90b6db780a9f05a425dc08941af6c3d099238ac3c9da
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 10e8e549da42808d727bc565aeadd200df095d09123e88d3ea203997c63af5d4647e2a6dc6cf47eafd9647647553c39e5f7883a5a029c9de1b84bb28907eab84
|
|
7
|
+
data.tar.gz: 342ab64adb46a6759cb0e695f87d5c9f3c269a40f279a22d9d5eeb709bd0b91b07ec54eb2c127035ea3a9a43c44e61c79d2e329c0a52b2f516a9da721ad75187
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.0] - 2026-09-04
|
|
4
|
+
|
|
5
|
+
- **`config.table_name_prefix`.** Prefix the gem-owned table when `dials`
|
|
6
|
+
collides with an existing table — `config.table_name_prefix = "zar_"`
|
|
7
|
+
names it `zar_dials`. The prefix is used verbatim (trailing underscore
|
|
8
|
+
included), mirroring Rails' `table_name_prefix` convention. The install
|
|
9
|
+
generator takes the same prefix (`rails g dials:install
|
|
10
|
+
--table-name-prefix=zar_`) so the migration and initializer match.
|
|
11
|
+
|
|
3
12
|
## [0.1.0] - 2026-09-02
|
|
4
13
|
|
|
5
14
|
Initial release.
|
|
@@ -34,7 +34,11 @@ module Dials
|
|
|
34
34
|
# "ke") as one stream — don't declare dimension enums that differ only
|
|
35
35
|
# by case, or give the table a binary collation.
|
|
36
36
|
class Entry < ::ActiveRecord::Base
|
|
37
|
-
|
|
37
|
+
# Prefixable via Dials.configure { |c| c.table_name_prefix = "zar_" }
|
|
38
|
+
# for apps where "dials" collides with an existing table (see
|
|
39
|
+
# Config#table_name_prefix).
|
|
40
|
+
DEFAULT_TABLE_NAME = "dials"
|
|
41
|
+
self.table_name = DEFAULT_TABLE_NAME
|
|
38
42
|
|
|
39
43
|
validates :key, :scope, :seq, presence: true
|
|
40
44
|
validates :action, presence: true, inclusion: { in: %w[set clear] }
|
data/lib/dials/config.rb
CHANGED
|
@@ -19,11 +19,27 @@ module Dials
|
|
|
19
19
|
# and an explicit actor: always wins.
|
|
20
20
|
attr_accessor :default_actor
|
|
21
21
|
|
|
22
|
+
# Prefix for the gem-owned table, mirroring Rails' table_name_prefix
|
|
23
|
+
# convention: used verbatim, so include the trailing underscore
|
|
24
|
+
# ("ops_" makes the table "ops_dials"). nil (the default) keeps "dials".
|
|
25
|
+
# Set it when "dials" collides with an existing table, and pass the same
|
|
26
|
+
# prefix to the install generator (--table-name-prefix) so the migration
|
|
27
|
+
# matches.
|
|
28
|
+
attr_reader :table_name_prefix
|
|
29
|
+
|
|
22
30
|
def initialize
|
|
23
31
|
@store = nil
|
|
24
32
|
@cache_ttl = 5.0
|
|
25
33
|
@actor_label = Actor::DEFAULT_LABEL
|
|
26
34
|
@default_actor = nil
|
|
35
|
+
@table_name_prefix = nil
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Order-independent with store=: whichever runs second applies the name.
|
|
39
|
+
def table_name_prefix=(prefix)
|
|
40
|
+
@table_name_prefix = prefix
|
|
41
|
+
apply_table_name
|
|
42
|
+
Dials.reset_cache!
|
|
27
43
|
end
|
|
28
44
|
|
|
29
45
|
def cache_ttl=(seconds)
|
|
@@ -37,6 +53,7 @@ module Dials
|
|
|
37
53
|
when :memory then Stores::Memory.new
|
|
38
54
|
when :active_record
|
|
39
55
|
require "dials/active_record"
|
|
56
|
+
apply_table_name
|
|
40
57
|
Stores::ActiveRecordStore.new
|
|
41
58
|
else store
|
|
42
59
|
end
|
|
@@ -46,5 +63,14 @@ module Dials
|
|
|
46
63
|
def store
|
|
47
64
|
@store ||= Stores::Memory.new
|
|
48
65
|
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
def apply_table_name
|
|
70
|
+
return unless defined?(Dials::ActiveRecord::Entry)
|
|
71
|
+
|
|
72
|
+
Dials::ActiveRecord::Entry.table_name =
|
|
73
|
+
"#{@table_name_prefix}#{Dials::ActiveRecord::Entry::DEFAULT_TABLE_NAME}"
|
|
74
|
+
end
|
|
49
75
|
end
|
|
50
76
|
end
|
data/lib/dials/version.rb
CHANGED
|
@@ -7,15 +7,20 @@ module Dials
|
|
|
7
7
|
module Generators
|
|
8
8
|
# `bin/rails generate dials:install`
|
|
9
9
|
#
|
|
10
|
-
# Creates the migration for the
|
|
11
|
-
#
|
|
10
|
+
# Creates the migration for the gem-owned table and an initializer with
|
|
11
|
+
# a commented starter registry. --table-name-prefix prefixes the table
|
|
12
|
+
# (Rails table_name_prefix convention, trailing underscore included) for
|
|
13
|
+
# apps where "dials" collides with an existing one.
|
|
12
14
|
class InstallGenerator < Rails::Generators::Base
|
|
13
15
|
include ::ActiveRecord::Generators::Migration
|
|
14
16
|
|
|
15
17
|
source_root File.expand_path("templates", __dir__)
|
|
16
18
|
|
|
19
|
+
class_option :table_name_prefix, type: :string, default: "",
|
|
20
|
+
desc: 'Prefix for the gem-owned table, used verbatim ("zar_" creates zar_dials)'
|
|
21
|
+
|
|
17
22
|
def create_migration_file
|
|
18
|
-
migration_template "migration.rb.tt", "db/migrate/
|
|
23
|
+
migration_template "migration.rb.tt", "db/migrate/create_#{table_name}_table.rb"
|
|
19
24
|
end
|
|
20
25
|
|
|
21
26
|
def create_initializer
|
|
@@ -34,6 +39,12 @@ module Dials
|
|
|
34
39
|
|
|
35
40
|
TEXT
|
|
36
41
|
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def table_name
|
|
46
|
+
"#{options[:table_name_prefix]}dials"
|
|
47
|
+
end
|
|
37
48
|
end
|
|
38
49
|
end
|
|
39
50
|
end
|
|
@@ -3,11 +3,22 @@
|
|
|
3
3
|
require "dials/active_record"
|
|
4
4
|
|
|
5
5
|
Dials.configure do |config|
|
|
6
|
-
# Where values live. :active_record uses the
|
|
6
|
+
# Where values live. :active_record uses the table created by
|
|
7
7
|
# `rails g dials:install`; :memory keeps everything in-process (handy in
|
|
8
8
|
# test environments that never exercise persistence).
|
|
9
9
|
config.store = :active_record
|
|
10
10
|
|
|
11
|
+
<% if options[:table_name_prefix].empty? -%>
|
|
12
|
+
# Prefix the gem-owned table when "dials" collides with an existing one.
|
|
13
|
+
# Used verbatim, so include the trailing underscore. Must match the
|
|
14
|
+
# migration (`rails g dials:install --table-name-prefix=zar_`).
|
|
15
|
+
# config.table_name_prefix = "zar_"
|
|
16
|
+
<% else -%>
|
|
17
|
+
# Names the gem-owned table <%= table_name %>, as created by the install
|
|
18
|
+
# migration.
|
|
19
|
+
config.table_name_prefix = "<%= options[:table_name_prefix] %>"
|
|
20
|
+
<% end -%>
|
|
21
|
+
|
|
11
22
|
# Seconds between cache staleness probes (one cheap query per process per
|
|
12
23
|
# interval). 0 probes on every read; nil never probes.
|
|
13
24
|
# config.cache_ttl = 5.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class Create<%= table_name.camelize %>Table < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
|
|
4
4
|
def change
|
|
5
5
|
# The gem's ONE table, append-only: every write INSERTs a row, and the
|
|
6
6
|
# newest row per (key, scope) stream is the current override — action
|
|
@@ -22,7 +22,7 @@ class CreateDialsTables < ActiveRecord::Migration[<%= ActiveRecord::Migration.cu
|
|
|
22
22
|
# a binary collation there. PostgreSQL and SQLite compare bytes already.
|
|
23
23
|
identity_collation = ("utf8mb4_bin" if connection.adapter_name.match?(/mysql/i))
|
|
24
24
|
|
|
25
|
-
create_table
|
|
25
|
+
create_table :<%= table_name %> do |t|
|
|
26
26
|
t.string :key, null: false, limit: 100, collation: identity_collation
|
|
27
27
|
t.string :scope, null: false, limit: 255, collation: identity_collation
|
|
28
28
|
t.bigint :seq, null: false
|
|
@@ -33,7 +33,7 @@ class CreateDialsTables < ActiveRecord::Migration[<%= ActiveRecord::Migration.cu
|
|
|
33
33
|
t.string :actor_label
|
|
34
34
|
t.datetime :created_at, null: false
|
|
35
35
|
end
|
|
36
|
-
add_index
|
|
37
|
-
add_index
|
|
36
|
+
add_index :<%= table_name %>, [:key, :scope, :seq], unique: true
|
|
37
|
+
add_index :<%= table_name %>, :key
|
|
38
38
|
end
|
|
39
39
|
end
|