support_table_data 1.4.0 → 1.5.1

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/ARCHITECTURE.md +538 -0
  3. data/CHANGELOG.md +21 -0
  4. data/README.md +52 -5
  5. data/VERSION +1 -1
  6. data/lib/support_table_data/documentation/source_file.rb +98 -0
  7. data/lib/support_table_data/documentation/yard_doc.rb +91 -0
  8. data/lib/support_table_data/documentation.rb +9 -0
  9. data/lib/support_table_data/railtie.rb +22 -1
  10. data/lib/support_table_data/validation_error.rb +16 -0
  11. data/lib/support_table_data.rb +71 -53
  12. data/lib/tasks/support_table_data.rake +61 -12
  13. data/lib/tasks/utils.rb +71 -0
  14. data/support_table_data.gemspec +2 -1
  15. data/test_app/.gitignore +4 -0
  16. data/test_app/Gemfile +7 -0
  17. data/test_app/Rakefile +6 -0
  18. data/test_app/app/models/application_record.rb +5 -0
  19. data/test_app/app/models/secondary_application_record.rb +7 -0
  20. data/test_app/app/models/status.rb +120 -0
  21. data/test_app/app/models/thing.rb +10 -0
  22. data/test_app/bin/rails +4 -0
  23. data/test_app/config/application.rb +42 -0
  24. data/test_app/config/boot.rb +3 -0
  25. data/test_app/config/database.yml +17 -0
  26. data/test_app/config/environment.rb +5 -0
  27. data/test_app/config/environments/development.rb +11 -0
  28. data/test_app/config/environments/test.rb +11 -0
  29. data/test_app/config.ru +6 -0
  30. data/test_app/db/migrate/20260103060951_create_status.rb +8 -0
  31. data/test_app/db/schema.rb +20 -0
  32. data/test_app/db/secondary_migrate/20260104000001_create_things.rb +7 -0
  33. data/test_app/db/secondary_schema.rb +25 -0
  34. data/test_app/db/support_tables/statuses.yml +19 -0
  35. data/test_app/db/support_tables/things.yml +5 -0
  36. data/test_app/lib/tasks/database.rake +11 -0
  37. data/test_app/log/.keep +0 -0
  38. metadata +33 -8
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class SecondaryApplicationRecord < ApplicationRecord
4
+ self.abstract_class = true
5
+
6
+ connects_to database: {writing: :secondary, reading: :secondary}
7
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Status < ApplicationRecord
4
+ include SupportTableData
5
+
6
+ self.support_table_key_attribute = :code
7
+ add_support_table_data "statuses.yml"
8
+ named_instance_attribute_helpers :name
9
+
10
+ validates :code, presence: true, uniqueness: true
11
+ end
12
+
13
+ # Begin YARD docs for support_table_data
14
+ # To update these docs, run `bundle exec rake support_table_data:yard_docs`
15
+ class Status
16
+ # @!group Named Instances
17
+
18
+ # Find the named instance +active+ from the database.
19
+ #
20
+ # @!method self.active
21
+ # @return [Status]
22
+ # @raise [ActiveRecord::RecordNotFound] if the record does not exist
23
+ # @!visibility public
24
+
25
+ # Check if this record is the named instance +active+.
26
+ #
27
+ # @!method active?
28
+ # @return [Boolean]
29
+ # @!visibility public
30
+
31
+ # Get the name attribute from the data file
32
+ # for the named instance +active+.
33
+ #
34
+ # @!method self.active_name
35
+ # @return [Object]
36
+ # @!visibility public
37
+
38
+ # Find the named instance +canceled+ from the database.
39
+ #
40
+ # @!method self.canceled
41
+ # @return [Status]
42
+ # @raise [ActiveRecord::RecordNotFound] if the record does not exist
43
+ # @!visibility public
44
+
45
+ # Check if this record is the named instance +canceled+.
46
+ #
47
+ # @!method canceled?
48
+ # @return [Boolean]
49
+ # @!visibility public
50
+
51
+ # Get the name attribute from the data file
52
+ # for the named instance +canceled+.
53
+ #
54
+ # @!method self.canceled_name
55
+ # @return [Object]
56
+ # @!visibility public
57
+
58
+ # Find the named instance +completed+ from the database.
59
+ #
60
+ # @!method self.completed
61
+ # @return [Status]
62
+ # @raise [ActiveRecord::RecordNotFound] if the record does not exist
63
+ # @!visibility public
64
+
65
+ # Check if this record is the named instance +completed+.
66
+ #
67
+ # @!method completed?
68
+ # @return [Boolean]
69
+ # @!visibility public
70
+
71
+ # Get the name attribute from the data file
72
+ # for the named instance +completed+.
73
+ #
74
+ # @!method self.completed_name
75
+ # @return [Object]
76
+ # @!visibility public
77
+
78
+ # Find the named instance +failed+ from the database.
79
+ #
80
+ # @!method self.failed
81
+ # @return [Status]
82
+ # @raise [ActiveRecord::RecordNotFound] if the record does not exist
83
+ # @!visibility public
84
+
85
+ # Check if this record is the named instance +failed+.
86
+ #
87
+ # @!method failed?
88
+ # @return [Boolean]
89
+ # @!visibility public
90
+
91
+ # Get the name attribute from the data file
92
+ # for the named instance +failed+.
93
+ #
94
+ # @!method self.failed_name
95
+ # @return [Object]
96
+ # @!visibility public
97
+
98
+ # Find the named instance +pending+ from the database.
99
+ #
100
+ # @!method self.pending
101
+ # @return [Status]
102
+ # @raise [ActiveRecord::RecordNotFound] if the record does not exist
103
+ # @!visibility public
104
+
105
+ # Check if this record is the named instance +pending+.
106
+ #
107
+ # @!method pending?
108
+ # @return [Boolean]
109
+ # @!visibility public
110
+
111
+ # Get the name attribute from the data file
112
+ # for the named instance +pending+.
113
+ #
114
+ # @!method self.pending_name
115
+ # @return [Object]
116
+ # @!visibility public
117
+
118
+ # @!endgroup
119
+ end
120
+ # End YARD docs for support_table_data
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Thing < SecondaryApplicationRecord
4
+ include SupportTableData
5
+
6
+ self.support_table_key_attribute = :id
7
+ add_support_table_data "things.yml"
8
+
9
+ validates :name, presence: true, uniqueness: true
10
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path("../config/application", __dir__)
3
+ require_relative "../config/boot"
4
+ require "rails/commands"
@@ -0,0 +1,42 @@
1
+ require_relative "boot"
2
+
3
+ require "rails"
4
+ # Pick the frameworks you want:
5
+ # require "active_model/railtie"
6
+ # require "active_job/railtie"
7
+ require "active_record/railtie"
8
+ # require "active_storage/engine"
9
+ # require "action_controller/railtie"
10
+ # require "action_mailer/railtie"
11
+ # require "action_mailbox/engine"
12
+ # require "action_text/engine"
13
+ # require "action_view/railtie"
14
+ # require "action_cable/engine"
15
+ # require "rails/test_unit/railtie"
16
+
17
+ # Require the gems listed in Gemfile, including any gems
18
+ # you've limited to :test, :development, or :production.
19
+ Bundler.require(*Rails.groups)
20
+
21
+ module TestApp
22
+ class Application < Rails::Application
23
+ # Initialize configuration defaults for originally generated Rails version.
24
+ config.load_defaults 8.1
25
+
26
+ # Please, add to the `ignore` list any other `lib` subdirectories that do
27
+ # not contain `.rb` files, or that should not be reloaded or eager loaded.
28
+ # Common ones are `templates`, `generators`, or `middleware`, for example.
29
+ config.autoload_lib(ignore: %w[assets tasks])
30
+
31
+ # Configuration for the application, engines, and railties goes here.
32
+ #
33
+ # These settings can be overridden in specific environments using the files
34
+ # in config/environments, which are processed later.
35
+ #
36
+ # config.time_zone = "Central Time (US & Canada)"
37
+ config.eager_load_paths << Rails.root.join("app", "configurations")
38
+
39
+ # Don't generate system test files.
40
+ config.generators.system_tests = nil
41
+ end
42
+ end
@@ -0,0 +1,3 @@
1
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
2
+
3
+ require "bundler/setup" # Set up gems listed in the Gemfile.
@@ -0,0 +1,17 @@
1
+ development:
2
+ primary:
3
+ adapter: sqlite3
4
+ database: db/development.sqlite3
5
+ secondary:
6
+ adapter: sqlite3
7
+ database: db/secondary_development.sqlite3
8
+ migrations_paths: db/secondary_migrate
9
+
10
+ test:
11
+ primary:
12
+ adapter: sqlite3
13
+ database: db/test.sqlite3
14
+ secondary:
15
+ adapter: sqlite3
16
+ database: db/secondary_test.sqlite3
17
+ migrations_paths: db/secondary_migrate
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require_relative "application"
3
+
4
+ # Initialize the Rails application.
5
+ Rails.application.initialize!
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.configure do
4
+ # Settings specified here will take precedence over those in config/application.rb.
5
+
6
+ # Make code changes take effect immediately without server restart.
7
+ config.enable_reloading = true
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.configure do
4
+ # Settings specified here will take precedence over those in config/application.rb.
5
+
6
+ # Make code changes take effect immediately without server restart.
7
+ config.enable_reloading = true
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+ end
@@ -0,0 +1,6 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require_relative "config/environment"
4
+
5
+ # run Rails.application
6
+ # Rails.application.load_server
@@ -0,0 +1,8 @@
1
+ class CreateStatus < ActiveRecord::Migration[8.1]
2
+ def change
3
+ create_table :statuses do |t|
4
+ t.string :code, null: false, index: {unique: true}
5
+ t.string :name, null: false, index: {unique: true}
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema[8.1].define(version: 2026_01_03_060951) do
14
+ create_table "statuses", force: :cascade do |t|
15
+ t.string "code", null: false
16
+ t.string "name", null: false
17
+ t.index ["code"], name: "index_statuses_on_code", unique: true
18
+ t.index ["name"], name: "index_statuses_on_name", unique: true
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ class CreateThings < ActiveRecord::Migration[8.1]
2
+ def change
3
+ create_table :things do |t|
4
+ t.string :name, null: false, index: {unique: true}
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,25 @@
1
+ # This file is auto-generated from the current state of the database. Instead
2
+ # of editing this file, please use the migrations feature of Active Record to
3
+ # incrementally modify your database, and then regenerate this schema definition.
4
+ #
5
+ # This file is the source Rails uses to define your schema when running `bin/rails
6
+ # db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7
+ # be faster and is potentially less error prone than running all of your
8
+ # migrations from scratch. Old migrations may fail to apply correctly if those
9
+ # migrations use external dependencies or application code.
10
+ #
11
+ # It's strongly recommended that you check this file into your version control system.
12
+
13
+ ActiveRecord::Schema[8.1].define(version: 2026_01_04_000001) do
14
+ create_table "statuses", force: :cascade do |t|
15
+ t.string "code", null: false
16
+ t.string "name", null: false
17
+ t.index ["code"], name: "index_statuses_on_code", unique: true
18
+ t.index ["name"], name: "index_statuses_on_name", unique: true
19
+ end
20
+
21
+ create_table "things", force: :cascade do |t|
22
+ t.string "name", null: false
23
+ t.index ["name"], name: "index_things_on_name", unique: true
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ pending:
2
+ code: pending
3
+ name: Pending
4
+
5
+ active:
6
+ code: active
7
+ name: Active
8
+
9
+ completed:
10
+ code: completed
11
+ name: Completed
12
+
13
+ canceled:
14
+ code: canceled
15
+ name: Canceled
16
+
17
+ failed:
18
+ code: failed
19
+ name: Failed
@@ -0,0 +1,5 @@
1
+ - id: 1
2
+ name: Thing One
3
+
4
+ - id: 2
5
+ name: Thing Two
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ if Rake::Task.task_defined?("db:migrate")
4
+ Rake::Task["db:migrate"].enhance do
5
+ # The main database connection may have artifacts from the migration, so re-establish it
6
+ # to get a clean connection before syncing support table data.
7
+ ActiveRecord::Base.establish_connection
8
+
9
+ Rake::Task["support_table_data:sync"].invoke
10
+ end
11
+ end
File without changes
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: support_table_data
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-05-01 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activerecord
@@ -38,29 +37,56 @@ dependencies:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
41
- description:
42
40
  email:
43
41
  - bbdurand@gmail.com
44
42
  executables: []
45
43
  extensions: []
46
44
  extra_rdoc_files: []
47
45
  files:
46
+ - ARCHITECTURE.md
48
47
  - CHANGELOG.md
49
48
  - MIT-LICENSE.txt
50
49
  - README.md
51
50
  - VERSION
52
51
  - lib/support_table_data.rb
52
+ - lib/support_table_data/documentation.rb
53
+ - lib/support_table_data/documentation/source_file.rb
54
+ - lib/support_table_data/documentation/yard_doc.rb
53
55
  - lib/support_table_data/railtie.rb
56
+ - lib/support_table_data/validation_error.rb
54
57
  - lib/tasks/support_table_data.rake
58
+ - lib/tasks/utils.rb
55
59
  - support_table_data.gemspec
60
+ - test_app/.gitignore
61
+ - test_app/Gemfile
62
+ - test_app/Rakefile
63
+ - test_app/app/models/application_record.rb
64
+ - test_app/app/models/secondary_application_record.rb
65
+ - test_app/app/models/status.rb
66
+ - test_app/app/models/thing.rb
67
+ - test_app/bin/rails
68
+ - test_app/config.ru
69
+ - test_app/config/application.rb
70
+ - test_app/config/boot.rb
71
+ - test_app/config/database.yml
72
+ - test_app/config/environment.rb
73
+ - test_app/config/environments/development.rb
74
+ - test_app/config/environments/test.rb
75
+ - test_app/db/migrate/20260103060951_create_status.rb
76
+ - test_app/db/schema.rb
77
+ - test_app/db/secondary_migrate/20260104000001_create_things.rb
78
+ - test_app/db/secondary_schema.rb
79
+ - test_app/db/support_tables/statuses.yml
80
+ - test_app/db/support_tables/things.yml
81
+ - test_app/lib/tasks/database.rake
82
+ - test_app/log/.keep
56
83
  homepage: https://github.com/bdurand/support_table_data
57
84
  licenses:
58
85
  - MIT
59
86
  metadata:
60
87
  homepage_uri: https://github.com/bdurand/support_table_data
61
88
  source_code_uri: https://github.com/bdurand/support_table_data
62
- changelog_uri: https://github.com/bdurand/support_table_data/blob/master/CHANGELOG.md
63
- post_install_message:
89
+ changelog_uri: https://github.com/bdurand/support_table_data/blob/main/CHANGELOG.md
64
90
  rdoc_options: []
65
91
  require_paths:
66
92
  - lib
@@ -75,8 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
101
  - !ruby/object:Gem::Version
76
102
  version: '0'
77
103
  requirements: []
78
- rubygems_version: 3.4.10
79
- signing_key:
104
+ rubygems_version: 4.0.3
80
105
  specification_version: 4
81
106
  summary: Extension for ActiveRecord models to manage synchronizing data in support/lookup
82
107
  tables across environments. Also provides the ability to directly reference and