meta_states 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.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +46 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +255 -0
  5. data/lib/generators/meta_states/install/install_generator.rb +43 -0
  6. data/lib/generators/meta_states/install/templates/create_indexes_on_meta_states_states.rb.erb +11 -0
  7. data/lib/generators/meta_states/install/templates/create_meta_states_states.rb.erb +18 -0
  8. data/lib/generators/meta_states/install/templates/initializer.rb.erb +42 -0
  9. data/lib/meta_states/base.rb +70 -0
  10. data/lib/meta_states/callback.rb +58 -0
  11. data/lib/meta_states/configuration/model_configuration.rb +64 -0
  12. data/lib/meta_states/configuration/state_type_configuration.rb +17 -0
  13. data/lib/meta_states/configuration.rb +142 -0
  14. data/lib/meta_states/railtie.rb +8 -0
  15. data/lib/meta_states/state.rb +5 -0
  16. data/lib/meta_states/stateable.rb +26 -0
  17. data/lib/meta_states/version.rb +5 -0
  18. data/lib/meta_states.rb +25 -0
  19. data/spec/dummy/Gemfile +40 -0
  20. data/spec/dummy/Gemfile.lock +308 -0
  21. data/spec/dummy/README.md +24 -0
  22. data/spec/dummy/Rakefile +8 -0
  23. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  24. data/spec/dummy/app/jobs/application_job.rb +9 -0
  25. data/spec/dummy/app/models/application_record.rb +5 -0
  26. data/spec/dummy/app/models/company.rb +3 -0
  27. data/spec/dummy/app/models/user.rb +3 -0
  28. data/spec/dummy/bin/brakeman +9 -0
  29. data/spec/dummy/bin/dev +4 -0
  30. data/spec/dummy/bin/docker-entrypoint +14 -0
  31. data/spec/dummy/bin/rails +6 -0
  32. data/spec/dummy/bin/rake +6 -0
  33. data/spec/dummy/bin/rubocop +10 -0
  34. data/spec/dummy/bin/setup +36 -0
  35. data/spec/dummy/bin/thrust +7 -0
  36. data/spec/dummy/config/application.rb +27 -0
  37. data/spec/dummy/config/boot.rb +5 -0
  38. data/spec/dummy/config/credentials.yml.enc +1 -0
  39. data/spec/dummy/config/database.yml +37 -0
  40. data/spec/dummy/config/environment.rb +7 -0
  41. data/spec/dummy/config/environments/development.rb +54 -0
  42. data/spec/dummy/config/environments/production.rb +69 -0
  43. data/spec/dummy/config/environments/test.rb +44 -0
  44. data/spec/dummy/config/initializers/cors.rb +18 -0
  45. data/spec/dummy/config/initializers/filter_parameter_logging.rb +10 -0
  46. data/spec/dummy/config/initializers/inflections.rb +18 -0
  47. data/spec/dummy/config/initializers/meta_states.rb +45 -0
  48. data/spec/dummy/config/locales/en.yml +31 -0
  49. data/spec/dummy/config/master.key +1 -0
  50. data/spec/dummy/config/puma.rb +43 -0
  51. data/spec/dummy/config/routes.rb +12 -0
  52. data/spec/dummy/config.ru +8 -0
  53. data/spec/dummy/db/migrate/20241221171423_create_test_models.rb +15 -0
  54. data/spec/dummy/db/migrate/20241223212128_create_has_states_states.rb +18 -0
  55. data/spec/dummy/db/migrate/20250114175939_create_indexes_on_has_states_states.rb +10 -0
  56. data/spec/dummy/db/schema.rb +44 -0
  57. data/spec/dummy/db/seeds.rb +11 -0
  58. data/spec/dummy/log/development.log +416 -0
  59. data/spec/dummy/log/test.log +55143 -0
  60. data/spec/dummy/public/robots.txt +1 -0
  61. data/spec/dummy/storage/development.sqlite3 +0 -0
  62. data/spec/dummy/storage/test.sqlite3 +0 -0
  63. data/spec/dummy/tmp/local_secret.txt +1 -0
  64. data/spec/factories/meta_states.rb +19 -0
  65. data/spec/generators/meta_states/install_generator_spec.rb +27 -0
  66. data/spec/generators/templates/config/initializers/meta_states.rb +42 -0
  67. data/spec/generators/templates/db/migrate/20250605170637_create_indexes_on_meta_states_states.rb +11 -0
  68. data/spec/generators/templates/db/migrate/20250605170637_create_meta_states_states.rb +18 -0
  69. data/spec/meta_states/callback_spec.rb +92 -0
  70. data/spec/meta_states/configuration_spec.rb +218 -0
  71. data/spec/meta_states/state_limit_spec.rb +107 -0
  72. data/spec/meta_states/state_metadata_schema_spec.rb +75 -0
  73. data/spec/meta_states/state_spec.rb +349 -0
  74. data/spec/meta_states/stateable_spec.rb +183 -0
  75. data/spec/meta_states_spec.rb +52 -0
  76. data/spec/rails_helper.rb +19 -0
  77. data/spec/spec_helper.rb +16 -0
  78. data/spec/support/database_cleaner.rb +17 -0
  79. data/spec/support/factory_bot.rb +8 -0
  80. data/spec/support/shoulda_matchers.rb +10 -0
  81. data/spec/tmp/config/initializers/has_states.rb +12 -0
  82. data/spec/tmp/db/migrate/20241223004024_create_has_states_states.rb +20 -0
  83. metadata +141 -0
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'fileutils'
5
+
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args, exception: true)
10
+ end
11
+
12
+ FileUtils.chdir APP_ROOT do
13
+ # This script is a way to set up or update your development environment automatically.
14
+ # This script is idempotent, so that you can run it at any time and get an expectable outcome.
15
+ # Add necessary setup steps to this file.
16
+
17
+ puts '== Installing dependencies =='
18
+ system('bundle check') || system!('bundle install')
19
+
20
+ # puts "\n== Copying sample files =="
21
+ # unless File.exist?("config/database.yml")
22
+ # FileUtils.cp "config/database.yml.sample", "config/database.yml"
23
+ # end
24
+
25
+ puts "\n== Preparing database =="
26
+ system! 'bin/rails db:prepare'
27
+
28
+ puts "\n== Removing old logs and tempfiles =="
29
+ system! 'bin/rails log:clear tmp:clear'
30
+
31
+ unless ARGV.include?('--skip-server')
32
+ puts "\n== Starting development server =="
33
+ $stdout.flush # flush the output before exec(2) so that it displays
34
+ exec 'bin/dev'
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
+
7
+ load Gem.bin_path('thruster', 'thrust')
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'boot'
4
+
5
+ require 'rails'
6
+
7
+ # Pick the frameworks you want:
8
+ require 'active_model/railtie'
9
+ require 'active_record/railtie'
10
+ require 'action_controller/railtie'
11
+
12
+ # Require the gems listed in Gemfile, including any gems
13
+ # you've limited to :test, :development, or :production.
14
+ Bundler.require(*Rails.groups)
15
+
16
+ Bundler.require(*Rails.groups)
17
+ require 'meta_states'
18
+
19
+ module Dummy
20
+ class Application < Rails::Application
21
+ config.load_defaults Rails::VERSION::STRING.to_f
22
+
23
+ # For compatibility with applications that use this config
24
+ config.action_controller.include_all_helpers = false
25
+ config.api_only = false
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
4
+
5
+ require 'bundler/setup' # Set up gems listed in the Gemfile.
@@ -0,0 +1 @@
1
+ vmOmINHq7bJj1FHsrVmFX71HX0/WnquEOXY4wkZxVR3ZAXj1ldv0Edjc8RbQ28uO5k6BMPlLptwqmsEQ5t1cJhhsL57G+DJf3VYnPkJmO7BYwZx/u0vENfmc4yy7u/nCWyTznpR6OVcPUDCQAmWdEwPGjPOya3+wPW4kMV5Fv9wMUqAFJElXLkrmR9LTxnSTd9AJx6lxNIWACGga/7lfayXcln4cwWP/tFM8eX8OaBzKWpsgDH16W0nxLeTqtMbPbmrtfDBwjAkplxQPRhIV5flUWEFQ/dbRFP7KbFt3qeG5AL+/e4KdZbeRw4lDkK1xfV/fRgoSGjCP1PU6Cq8b8V/fyykbERqb3773Bl3736ANHLcJyDHTYQcque3haAu7UbzQcQ4XpHNKfGFODN/RxytWGvo2b62WspZ72O8CIIDcRXt/jMFrC5xNb03iT2tGmi5/50aLKSzMEAdjsb1nIP7nG949C3aeb/1FbQOrVcATdIH1MYrH8jgB--ascdYp/R50fY6srg--7y8YySI8auWbFGy4sG1Log==
@@ -0,0 +1,37 @@
1
+ # SQLite. Versions 3.8.0 and up are supported.
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem "sqlite3"
6
+ #
7
+ default: &default
8
+ adapter: sqlite3
9
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
10
+ timeout: 5000
11
+
12
+ development:
13
+ <<: *default
14
+ database: storage/development.sqlite3
15
+
16
+ # Warning: The database defined as "test" will be erased and
17
+ # re-generated from your development database when you run "rake".
18
+ # Do not set this db to the same as development or production.
19
+ test:
20
+ <<: *default
21
+ database: storage/test.sqlite3
22
+
23
+
24
+ # Store production database in the storage/ directory, which by default
25
+ # is mounted as a persistent Docker volume in config/deploy.yml.
26
+ production:
27
+ primary:
28
+ <<: *default
29
+ database: storage/production.sqlite3
30
+ cache:
31
+ <<: *default
32
+ database: storage/production_cache.sqlite3
33
+ migrations_paths: db/cache_migrate
34
+ queue:
35
+ <<: *default
36
+ database: storage/production_queue.sqlite3
37
+ migrations_paths: db/queue_migrate
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Load the Rails application.
4
+ require_relative 'application'
5
+
6
+ # Initialize the Rails application.
7
+ Rails.application.initialize!
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/integer/time'
4
+
5
+ Rails.application.configure do
6
+ # Settings specified here will take precedence over those in config/application.rb.
7
+
8
+ # Make code changes take effect immediately without server restart.
9
+ config.enable_reloading = true
10
+
11
+ # Do not eager load code on boot.
12
+ config.eager_load = false
13
+
14
+ # Show full error reports.
15
+ config.consider_all_requests_local = true
16
+
17
+ # Enable server timing.
18
+ config.server_timing = true
19
+
20
+ # Enable/disable Action Controller caching. By default Action Controller caching is disabled.
21
+ # Run rails dev:cache to toggle Action Controller caching.
22
+ if Rails.root.join('tmp/caching-dev.txt').exist?
23
+ config.public_file_server.headers = { 'cache-control' => "public, max-age=#{2.days.to_i}" }
24
+ else
25
+ config.action_controller.perform_caching = false
26
+ end
27
+
28
+ # Change to :null_store to avoid any caching.
29
+ config.cache_store = :memory_store
30
+
31
+ # Print deprecation notices to the Rails logger.
32
+ config.active_support.deprecation = :log
33
+
34
+ # Raise an error on page load if there are pending migrations.
35
+ config.active_record.migration_error = :page_load
36
+
37
+ # Highlight code that triggered database queries in logs.
38
+ config.active_record.verbose_query_logs = true
39
+
40
+ # Append comments with runtime information tags to SQL queries in logs.
41
+ config.active_record.query_log_tags_enabled = true
42
+
43
+ # Raises error for missing translations.
44
+ # config.i18n.raise_on_missing_translations = true
45
+
46
+ # Annotate rendered view with file names.
47
+ config.action_view.annotate_rendered_view_with_filenames = true
48
+
49
+ # Raise error when a before_action's only/except options reference missing actions.
50
+ config.action_controller.raise_on_missing_callback_actions = true
51
+
52
+ # Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
53
+ # config.generators.apply_rubocop_autocorrect_after_generate!
54
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/integer/time'
4
+
5
+ Rails.application.configure do
6
+ # Settings specified here will take precedence over those in config/application.rb.
7
+
8
+ # Code is not reloaded between requests.
9
+ config.enable_reloading = false
10
+
11
+ # Eager load code on boot for better performance and memory savings (ignored by Rake tasks).
12
+ config.eager_load = true
13
+
14
+ # Full error reports are disabled.
15
+ config.consider_all_requests_local = false
16
+
17
+ # Cache assets for far-future expiry since they are all digest stamped.
18
+ config.public_file_server.headers = { 'cache-control' => "public, max-age=#{1.year.to_i}" }
19
+
20
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
21
+ # config.asset_host = "http://assets.example.com"
22
+
23
+ # Assume all access to the app is happening through a SSL-terminating reverse proxy.
24
+ config.assume_ssl = true
25
+
26
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
27
+ config.force_ssl = true
28
+
29
+ # Skip http-to-https redirect for the default health check endpoint.
30
+ # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } }
31
+
32
+ # Log to STDOUT with the current request id as a default log tag.
33
+ config.log_tags = [:request_id]
34
+ config.logger = ActiveSupport::TaggedLogging.logger($stdout)
35
+
36
+ # Change to "debug" to log everything (including potentially personally-identifiable information!)
37
+ config.log_level = ENV.fetch('RAILS_LOG_LEVEL', 'info')
38
+
39
+ # Prevent health checks from clogging up the logs.
40
+ config.silence_healthcheck_path = '/up'
41
+
42
+ # Don't log any deprecations.
43
+ config.active_support.report_deprecations = false
44
+
45
+ # Replace the default in-process memory cache store with a durable alternative.
46
+ # config.cache_store = :mem_cache_store
47
+
48
+ # Replace the default in-process and non-durable queuing backend for Active Job.
49
+ # config.active_job.queue_adapter = :resque
50
+
51
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
52
+ # the I18n.default_locale when a translation cannot be found).
53
+ config.i18n.fallbacks = true
54
+
55
+ # Do not dump schema after migrations.
56
+ config.active_record.dump_schema_after_migration = false
57
+
58
+ # Only use :id for inspections in production.
59
+ config.active_record.attributes_for_inspect = [:id]
60
+
61
+ # Enable DNS rebinding protection and other `Host` header attacks.
62
+ # config.hosts = [
63
+ # "example.com", # Allow requests from example.com
64
+ # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com`
65
+ # ]
66
+ #
67
+ # Skip DNS rebinding protection for the default health check endpoint.
68
+ # config.host_authorization = { exclude: ->(request) { request.path == "/up" } }
69
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The test environment is used exclusively to run your application's
4
+ # test suite. You never need to work with it otherwise. Remember that
5
+ # your test database is "scratch space" for the test suite and is wiped
6
+ # and recreated between test runs. Don't rely on the data there!
7
+
8
+ Rails.application.configure do
9
+ # Settings specified here will take precedence over those in config/application.rb.
10
+
11
+ # While tests run files are not watched, reloading is not necessary.
12
+ config.enable_reloading = false
13
+
14
+ # Eager loading loads your entire application. When running a single test locally,
15
+ # this is usually not necessary, and can slow down your test suite. However, it's
16
+ # recommended that you enable it in continuous integration systems to ensure eager
17
+ # loading is working properly before deploying your code.
18
+ config.eager_load = ENV['CI'].present?
19
+
20
+ # Configure public file server for tests with cache-control for performance.
21
+ config.public_file_server.headers = { 'cache-control' => 'public, max-age=3600' }
22
+
23
+ # Show full error reports.
24
+ config.consider_all_requests_local = true
25
+ config.cache_store = :null_store
26
+
27
+ # Render exception templates for rescuable exceptions and raise for other exceptions.
28
+ config.action_dispatch.show_exceptions = :rescuable
29
+
30
+ # Disable request forgery protection in test environment.
31
+ config.action_controller.allow_forgery_protection = false
32
+
33
+ # Print deprecation notices to the stderr.
34
+ config.active_support.deprecation = :stderr
35
+
36
+ # Raises error for missing translations.
37
+ # config.i18n.raise_on_missing_translations = true
38
+
39
+ # Annotate rendered view with file names.
40
+ # config.action_view.annotate_rendered_view_with_filenames = true
41
+
42
+ # Raise error when a before_action's only/except options reference missing actions.
43
+ config.action_controller.raise_on_missing_callback_actions = true
44
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # Avoid CORS issues when API is called from the frontend app.
6
+ # Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin Ajax requests.
7
+
8
+ # Read more: https://github.com/cyu/rack-cors
9
+
10
+ # Rails.application.config.middleware.insert_before 0, Rack::Cors do
11
+ # allow do
12
+ # origins "example.com"
13
+ #
14
+ # resource "*",
15
+ # headers: :any,
16
+ # methods: [:get, :post, :put, :patch, :delete, :options, :head]
17
+ # end
18
+ # end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file.
6
+ # Use this to limit dissemination of sensitive information.
7
+ # See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors.
8
+ Rails.application.config.filter_parameters += %i[
9
+ passw email secret token _key crypt salt certificate otp ssn cvv cvc
10
+ ]
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Be sure to restart your server when you modify this file.
4
+
5
+ # Add new inflection rules using the following format. Inflections
6
+ # are locale specific, and you may define rules for as many different
7
+ # locales as you wish. All of these examples are active by default:
8
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
9
+ # inflect.plural /^(ox)$/i, "\\1en"
10
+ # inflect.singular /^(ox)en/i, "\\1"
11
+ # inflect.irregular "person", "people"
12
+ # inflect.uncountable %w( fish sheep )
13
+ # end
14
+
15
+ # These inflection rules are supported but not enabled by default:
16
+ # ActiveSupport::Inflector.inflections(:en) do |inflect|
17
+ # inflect.acronym "RESTful"
18
+ # end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Configure after the application is initialized
4
+ Rails.application.config.after_initialize do
5
+ MetaStates.configure do |config|
6
+ # Configure your models and their state types below
7
+ #
8
+ # Example configuration:
9
+ #
10
+ config.configure_model User do |model|
11
+ # KYC state type with its allowed statuses
12
+ model.state_type :kyc do |type|
13
+ type.statuses = [
14
+ 'pending', # Initial state
15
+ 'documents_required', # Waiting for user documents
16
+ 'under_review', # Documents being reviewed
17
+ 'approved', # KYC process completed successfully
18
+ 'rejected' # KYC process failed
19
+ ]
20
+ end
21
+
22
+ # Onboarding state type with different statuses
23
+ model.state_type :onboarding do |type|
24
+ type.statuses = [
25
+ 'pending', # Just started
26
+ 'email_verified', # Email verification complete
27
+ 'profile_complete', # User filled all required fields
28
+ 'completed' # Onboarding finished
29
+ ]
30
+ end
31
+ end
32
+ #
33
+ # config.configure_model Company do |model|
34
+ # model.state_type :verification do |type|
35
+ # type.statuses = [
36
+ # 'pending',
37
+ # 'documents_submitted',
38
+ # 'under_review',
39
+ # 'verified',
40
+ # 'rejected'
41
+ # ]
42
+ # end
43
+ # end
44
+ end
45
+ end
@@ -0,0 +1,31 @@
1
+ # Files in the config/locales directory are used for internationalization and
2
+ # are automatically loaded by Rails. If you want to use locales other than
3
+ # English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t "hello"
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t("hello") %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more about the API, please read the Rails Internationalization guide
20
+ # at https://guides.rubyonrails.org/i18n.html.
21
+ #
22
+ # Be aware that YAML interprets the following case-insensitive strings as
23
+ # booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings
24
+ # must be quoted to be interpreted as strings. For example:
25
+ #
26
+ # en:
27
+ # "yes": yup
28
+ # enabled: "ON"
29
+
30
+ en:
31
+ hello: "Hello world"
@@ -0,0 +1 @@
1
+ b71d1f5d6da2a66b244850869b544a9e
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This configuration file will be evaluated by Puma. The top-level methods that
4
+ # are invoked here are part of Puma's configuration DSL. For more information
5
+ # about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.
6
+ #
7
+ # Puma starts a configurable number of processes (workers) and each process
8
+ # serves each request in a thread from an internal thread pool.
9
+ #
10
+ # You can control the number of workers using ENV["WEB_CONCURRENCY"]. You
11
+ # should only set this value when you want to run 2 or more workers. The
12
+ # default is already 1.
13
+ #
14
+ # The ideal number of threads per worker depends both on how much time the
15
+ # application spends waiting for IO operations and on how much you wish to
16
+ # prioritize throughput over latency.
17
+ #
18
+ # As a rule of thumb, increasing the number of threads will increase how much
19
+ # traffic a given process can handle (throughput), but due to CRuby's
20
+ # Global VM Lock (GVL) it has diminishing returns and will degrade the
21
+ # response time (latency) of the application.
22
+ #
23
+ # The default is set to 3 threads as it's deemed a decent compromise between
24
+ # throughput and latency for the average Rails application.
25
+ #
26
+ # Any libraries that use a connection pool or another resource pool should
27
+ # be configured to provide at least as many connections as the number of
28
+ # threads. This includes Active Record's `pool` parameter in `database.yml`.
29
+ threads_count = ENV.fetch('RAILS_MAX_THREADS', 3)
30
+ threads threads_count, threads_count
31
+
32
+ # Specifies the `port` that Puma will listen on to receive requests; default is 3000.
33
+ port ENV.fetch('PORT', 3000)
34
+
35
+ # Allow puma to be restarted by `bin/rails restart` command.
36
+ plugin :tmp_restart
37
+
38
+ # Run the Solid Queue supervisor inside of Puma for single-server deployments
39
+ plugin :solid_queue if ENV['SOLID_QUEUE_IN_PUMA']
40
+
41
+ # Specify the PID file. Defaults to tmp/pids/server.pid in development.
42
+ # In other environments, only set the PID file if requested.
43
+ pidfile ENV['PIDFILE'] if ENV['PIDFILE']
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ Rails.application.routes.draw do
4
+ # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
5
+
6
+ # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
7
+ # Can be used by load balancers and uptime monitors to verify that the app is live.
8
+ get 'up' => 'rails/health#show', as: :rails_health_check
9
+
10
+ # Defines the root path route ("/")
11
+ # root "posts#index"
12
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is used by Rack-based servers to start the application.
4
+
5
+ require_relative 'config/environment'
6
+
7
+ run Rails.application
8
+ Rails.application.load_server
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateTestModels < ActiveRecord::Migration[8.0]
4
+ def change
5
+ create_table :users do |t|
6
+ t.string :name
7
+ t.timestamps
8
+ end
9
+
10
+ create_table :companies do |t|
11
+ t.string :name
12
+ t.timestamps
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ class CreateMetaStatesStates < ActiveRecord::Migration[8.0]
2
+ def change
3
+ create_table :meta_states_states do |t|
4
+ t.string :type, null: false
5
+ t.string :state_type
6
+ t.string :status, null: false
7
+
8
+ t.json :metadata, null: false, default: {}
9
+
10
+ t.references :stateable, polymorphic: true, null: false
11
+
12
+ t.timestamps
13
+
14
+ t.index %i[type stateable_id]
15
+ t.index %i[stateable_type stateable_id]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ class CreateIndexesOnMetaStatesStates < ActiveRecord::Migration[8.0]
2
+ def change
3
+ change_table :meta_states_states do |t|
4
+ t.index %i[stateable_id state_type]
5
+ t.index %i[stateable_id state_type status]
6
+ t.index %i[stateable_id state_type created_at]
7
+ t.index %i[stateable_id state_type status created_at]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,44 @@
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.0].define(version: 2025_01_14_175939) do
14
+ create_table "companies", force: :cascade do |t|
15
+ t.string "name"
16
+ t.datetime "created_at", null: false
17
+ t.datetime "updated_at", null: false
18
+ end
19
+
20
+ create_table "meta_states_states", force: :cascade do |t|
21
+ t.string "type", null: false
22
+ t.string "state_type"
23
+ t.string "status", null: false
24
+ t.json "metadata", default: {}, null: false
25
+ t.string "stateable_type", null: false
26
+ t.integer "stateable_id", null: false
27
+ t.datetime "completed_at"
28
+ t.datetime "created_at", null: false
29
+ t.datetime "updated_at", null: false
30
+ t.index ["stateable_id", "state_type", "created_at"], name: "idx_on_stateable_id_state_type_created_at_b5d09fb6ee"
31
+ t.index ["stateable_id", "state_type", "status", "created_at"], name: "idx_on_stateable_id_state_type_status_created_at_19e1cf37c2"
32
+ t.index ["stateable_id", "state_type", "status"], name: "idx_on_stateable_id_state_type_status_6d3d026e4d"
33
+ t.index ["stateable_id", "state_type"], name: "index_meta_states_states_on_stateable_id_and_state_type"
34
+ t.index ["stateable_type", "stateable_id"], name: "index_meta_states_states_on_stateable"
35
+ t.index ["stateable_type", "stateable_id"], name: "index_meta_states_states_on_stateable_type_and_stateable_id"
36
+ t.index ["type", "stateable_id"], name: "index_meta_states_states_on_type_and_stateable_id"
37
+ end
38
+
39
+ create_table "users", force: :cascade do |t|
40
+ t.string "name"
41
+ t.datetime "created_at", null: false
42
+ t.datetime "updated_at", null: false
43
+ end
44
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file should ensure the existence of records required to run the application in every environment (production,
4
+ # development, test). The code here should be idempotent so that it can be executed at any point in every environment.
5
+ # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
6
+ #
7
+ # Example:
8
+ #
9
+ # ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
10
+ # MovieGenre.find_or_create_by!(name: genre_name)
11
+ # end