pg_rls 0.2.5 → 1.0.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/.rubocop.yml +55 -17
- data/.ruby-version +1 -0
- data/CHANGELOG.md +19 -2
- data/CODE_OF_CONDUCT.md +77 -29
- data/Guardfile +44 -0
- data/README.md +247 -83
- data/Rakefile +5 -12
- data/Steepfile +29 -0
- data/UPGRADE.md +106 -0
- data/app/models/pg_rls/admin.rb +24 -0
- data/app/models/pg_rls/current.rb +48 -0
- data/app/models/pg_rls/record.rb +13 -0
- data/app/models/pg_rls/tenant/searchable.rb +60 -0
- data/app/models/pg_rls/tenant/securable.rb +67 -0
- data/app/models/pg_rls/tenant/switchable.rb +40 -0
- data/app/models/pg_rls/tenant.rb +9 -0
- data/assets/logo.svg +8 -0
- data/docker-compose.yml +14 -0
- data/lib/generators/pg_rls/active_record/active_record_generator.rb +62 -65
- data/lib/generators/pg_rls/install/install_generator.rb +38 -0
- data/lib/generators/pg_rls/pg_rls_generator.rb +2 -1
- data/lib/generators/pg_rls/templates/USAGE +28 -0
- data/lib/generators/pg_rls/templates/app/models/abstract_base_class.rb.tt +7 -0
- data/lib/generators/pg_rls/templates/app/models/model.rb.tt +22 -0
- data/lib/generators/pg_rls/templates/config/initializers/pg_rls.rb.tt +58 -0
- data/lib/generators/pg_rls/templates/db/migrate/backport_pg_rls_table.rb.tt +14 -0
- data/lib/generators/pg_rls/templates/db/migrate/convert_to_pg_rls_table.rb.tt +5 -0
- data/lib/generators/pg_rls/templates/db/migrate/convert_to_pg_rls_tenant_table.rb.tt +5 -0
- data/lib/generators/pg_rls/templates/db/migrate/create_pg_rls_table.rb.tt +29 -0
- data/lib/generators/pg_rls/templates/db/migrate/create_pg_rls_tenant_table.rb.tt +29 -0
- data/lib/pg_rls/active_record/connection_adapters/connection_pool.rb +31 -0
- data/lib/pg_rls/active_record/connection_adapters/postgre_sql/check_rls_user_privileges.rb +207 -0
- data/lib/pg_rls/active_record/connection_adapters/postgre_sql/errors.rb +17 -0
- data/lib/pg_rls/active_record/connection_adapters/postgre_sql/grant_rls_user_privileges.rb +167 -0
- data/lib/pg_rls/active_record/connection_adapters/postgre_sql/rls_functions.rb +91 -0
- data/lib/pg_rls/active_record/connection_adapters/postgre_sql/rls_policies.rb +56 -0
- data/lib/pg_rls/active_record/connection_adapters/postgre_sql/rls_triggers.rb +95 -0
- data/lib/pg_rls/active_record/connection_adapters/postgre_sql/rls_user_statements.rb +127 -0
- data/lib/pg_rls/active_record/connection_adapters/postgre_sql/schema_dumper.rb +71 -0
- data/lib/pg_rls/active_record/connection_adapters/postgre_sql/schema_statements.rb +120 -0
- data/lib/pg_rls/active_record/connection_adapters/postgre_sql/sql_helper_method.rb +30 -0
- data/lib/pg_rls/active_record/connection_adapters/postgre_sql.rb +36 -0
- data/lib/pg_rls/active_record/connection_adapters.rb +12 -0
- data/lib/pg_rls/active_record/database_shards.rb +74 -0
- data/lib/pg_rls/active_record/migration/command_recorder.rb +28 -0
- data/lib/pg_rls/active_record/migration.rb +11 -0
- data/lib/pg_rls/active_record/test_databases.rb +19 -0
- data/lib/pg_rls/active_record.rb +11 -0
- data/lib/pg_rls/active_support/string_ext.rb +17 -0
- data/lib/pg_rls/active_support.rb +9 -0
- data/lib/pg_rls/connection_config.rb +61 -0
- data/lib/pg_rls/deprecation.rb +14 -0
- data/lib/pg_rls/engine.rb +8 -0
- data/lib/pg_rls/error.rb +10 -0
- data/lib/pg_rls/generators/.keep +0 -0
- data/lib/pg_rls/railtie.rb +1 -11
- data/lib/pg_rls/tasks/.keep +0 -0
- data/lib/pg_rls/version.rb +3 -1
- data/lib/pg_rls.rb +67 -151
- data/rbs_collection.lock.yaml +132 -0
- data/rbs_collection.yaml +127 -0
- data/review_code.sh +33 -0
- data/sig/generators/pg_rls/active_record/active_record_generator.rbs +43 -0
- data/sig/generators/pg_rls/install/install_generator.rbs +20 -0
- data/sig/generators/pg_rls/pg_rls_generator.rbs +9 -0
- data/sig/pg_rls/active_record/connection_adapters/postgre_sql/check_rls_user_privileges.rbs +53 -0
- data/sig/pg_rls/active_record/connection_adapters/postgre_sql/errors.rbs +24 -0
- data/sig/pg_rls/active_record/connection_adapters/postgre_sql/grant_rls_user_privileges.rbs +55 -0
- data/sig/pg_rls/active_record/connection_adapters/postgre_sql/rls_functions.rbs +31 -0
- data/sig/pg_rls/active_record/connection_adapters/postgre_sql/rls_policies.rbs +28 -0
- data/sig/pg_rls/active_record/connection_adapters/postgre_sql/rls_triggers.rbs +35 -0
- data/sig/pg_rls/active_record/connection_adapters/postgre_sql/rls_user_statements.rbs +48 -0
- data/sig/pg_rls/active_record/connection_adapters/postgre_sql/schema_dumper.rbs +38 -0
- data/sig/pg_rls/active_record/connection_adapters/postgre_sql/schema_statements.rbs +67 -0
- data/sig/pg_rls/active_record/connection_adapters/postgre_sql/sql_helper_method.rbs +21 -0
- data/sig/pg_rls/active_record/connection_adapters/postgresql.rbs +10 -0
- data/sig/pg_rls/active_record/connection_adapters.rbs +50 -0
- data/sig/pg_rls/active_record/database_shards.rbs +34 -0
- data/sig/pg_rls/active_record/migration/command_recorder.rbs +14 -0
- data/sig/pg_rls/active_record/migration.rbs +8 -0
- data/sig/pg_rls/active_record.rbs +7 -0
- data/sig/pg_rls/active_support/hash_ext.rbs +11 -0
- data/sig/pg_rls/active_support/string_ext.rbs +27 -0
- data/sig/pg_rls/active_support.rbs +7 -0
- data/sig/pg_rls/app/models/pg_rls/record.rbs +4 -0
- data/sig/pg_rls/connection_config.rbs +16 -0
- data/sig/pg_rls/deprecation.rbs +9 -0
- data/sig/pg_rls/engine.rbs +7 -0
- data/sig/pg_rls/errors.rbs +14 -0
- data/sig/pg_rls/railtie.rbs +6 -0
- data/sig/pg_rls/tenant_test_helper.rbs +14 -0
- data/sig/pg_rls.rbs +60 -0
- data/sig/support/active_record.rbs +86 -0
- data/sig/support/active_support.rbs +7 -0
- data/sig/support/fowardable.rbs +2 -0
- data/sig/support/pg.rbs +12 -0
- data/sig/support/rails.rbs +38 -0
- data/start.sh +30 -0
- metadata +167 -12
- data/Gemfile +0 -21
- data/Gemfile.lock +0 -300
- data/bin/console +0 -15
- data/bin/setup +0 -8
data/lib/pg_rls/railtie.rb
CHANGED
@@ -1,16 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '../pg_rls'
|
4
|
-
require 'rails'
|
5
|
-
|
6
3
|
module PgRls
|
7
|
-
|
8
|
-
class Railtie < Rails::Railtie
|
9
|
-
railtie_name :my_gem
|
10
|
-
|
11
|
-
rake_tasks do
|
12
|
-
path = File.dirname(__FILE__)
|
13
|
-
Dir.glob("#{path}/database/tasks/**/*.rake").each { |f| load f }
|
14
|
-
end
|
4
|
+
class Railtie < ::Rails::Railtie
|
15
5
|
end
|
16
6
|
end
|
File without changes
|
data/lib/pg_rls/version.rb
CHANGED
data/lib/pg_rls.rb
CHANGED
@@ -1,191 +1,107 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
require_relative
|
13
|
-
require_relative
|
14
|
-
|
15
|
-
|
16
|
-
require_relative 'pg_rls/logger'
|
17
|
-
|
18
|
-
ActiveRecord::Migrator.prepend PgRls::Admin::ActiveRecord::Migrator
|
19
|
-
ActiveRecord::Tasks::DatabaseTasks.prepend PgRls::Admin::ActiveRecord::Tasks::DatabaseTasks
|
20
|
-
ActiveRecord::ConnectionAdapters::AbstractAdapter.include PgRls::Schema::Statements
|
21
|
-
ActiveRecord::SchemaDumper.prepend PgRls::Schema::Dumper
|
22
|
-
|
23
|
-
# PostgreSQL Row Level Security
|
3
|
+
require "active_record"
|
4
|
+
require "forwardable"
|
5
|
+
|
6
|
+
require_relative "pg_rls/deprecation"
|
7
|
+
require_relative "pg_rls/error"
|
8
|
+
require_relative "pg_rls/active_record"
|
9
|
+
require_relative "pg_rls/active_support"
|
10
|
+
require_relative "pg_rls/version"
|
11
|
+
require_relative "pg_rls/engine"
|
12
|
+
require_relative "pg_rls/railtie"
|
13
|
+
require_relative "pg_rls/connection_config"
|
14
|
+
|
15
|
+
# Row Level Security for PostgreSQL
|
24
16
|
module PgRls
|
25
|
-
|
17
|
+
DEFAULT_CONFIG_MAP = {
|
18
|
+
"@@search_methods": %i[subdomain tenant_id id],
|
19
|
+
"@@table_name": :organizations,
|
20
|
+
"@@class_name": :Organization,
|
21
|
+
"@@username": :app_user,
|
22
|
+
"@@password": :password,
|
23
|
+
"@@schema": :public,
|
24
|
+
"@@rls_role_group": :rls_group,
|
25
|
+
"@@current_attributes": Array(nil),
|
26
|
+
"@@abstract_base_record_class": "ActiveRecord::Base"
|
27
|
+
}.freeze
|
28
|
+
|
26
29
|
class << self
|
27
30
|
extend Forwardable
|
28
31
|
|
29
|
-
WRITER_METHODS = %i[table_name class_name search_methods logger excluded_shards].freeze
|
30
|
-
READER_METHODS = %i[connection_class execute table_name class_name search_methods logger excluded_shards].freeze
|
31
|
-
DELEGATORS_METHODS = %i[connection_class execute table_name search_methods class_name main_model logger
|
32
|
-
excluded_shards].freeze
|
33
|
-
|
34
|
-
attr_writer(*WRITER_METHODS)
|
35
|
-
attr_reader(*READER_METHODS)
|
36
|
-
|
37
|
-
def_delegators(*DELEGATORS_METHODS)
|
38
|
-
|
39
32
|
def setup
|
40
|
-
|
41
|
-
|
42
|
-
yield self
|
43
|
-
|
33
|
+
PgRls.reset_config!
|
44
34
|
Rails.application.config.to_prepare do
|
45
|
-
PgRls.
|
35
|
+
PgRls::Record.ignored_columns += %w[tenant_id]
|
46
36
|
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def connection_class
|
50
|
-
@connection_class ||= ActiveRecord::Base
|
51
|
-
end
|
52
|
-
|
53
|
-
def admin_execute(query = nil, &)
|
54
|
-
current_tenant, reset_rls_connection = establish_admin_connection
|
55
|
-
execute_query_or_block(query, &)
|
56
|
-
ensure
|
57
|
-
reset_connection_if_needed(current_tenant, reset_rls_connection)
|
58
|
-
end
|
59
37
|
|
60
|
-
|
61
|
-
self.as_db_admin = admin
|
38
|
+
yield self
|
62
39
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
connection_class.establish_connection(pool.db_config)
|
67
|
-
end
|
40
|
+
connection_config = PgRls::ConnectionConfig.new
|
41
|
+
connection_config.look_up_connection_config unless connection_config.connection_config?
|
42
|
+
freeze_config! unless Rails.env.test?
|
68
43
|
end
|
69
44
|
|
70
45
|
def main_model
|
71
46
|
class_name.to_s.camelize.constantize
|
72
47
|
end
|
73
48
|
|
74
|
-
def
|
75
|
-
|
76
|
-
|
77
|
-
'Please use PgRls::Tenant.on_find_each instead.'
|
78
|
-
)
|
79
|
-
Tenant.on_find_each(ids:, scope:, &)
|
80
|
-
end
|
81
|
-
|
82
|
-
rails_version = Gem.loaded_specs['rails'].version
|
83
|
-
if rails_version >= Gem::Version.new('7.2') && rails_version < Gem::Version.new('7.3')
|
84
|
-
def pool_connection(pool)
|
85
|
-
pool.lease_connection
|
86
|
-
end
|
87
|
-
else
|
88
|
-
PgRls::Logger.new.deprecation_warning('PgRls.pool_connection is deprecated and will be removed in future PgRls 0.2.0. Please use pool.lease_connection instead.')
|
89
|
-
def pool_connection(pool)
|
90
|
-
pool.connection
|
49
|
+
def reset_config!
|
50
|
+
PgRls.class_variables.each do |var|
|
51
|
+
PgRls.class_variable_set(var, DEFAULT_CONFIG_MAP[var])
|
91
52
|
end
|
92
53
|
end
|
93
54
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
55
|
+
# :nocov:
|
56
|
+
def freeze_config! # rubocop:disable Metrics/MethodLength
|
57
|
+
PgRls.singleton_class.class_eval do
|
58
|
+
PgRls.class_variables.each do |var_name|
|
59
|
+
method_name = var_name.to_s.delete_prefix("@@").to_sym
|
60
|
+
setter_method_name = :"#{method_name}="
|
61
|
+
const_name = "#{method_name.to_s.upcase}_FROZEN_CONFIGURATION"
|
101
62
|
|
102
|
-
|
103
|
-
Rails.logger.info("Executing in #{connection.connection_class}")
|
63
|
+
remove_method setter_method_name if method_defined?(setter_method_name)
|
104
64
|
|
105
|
-
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
result
|
110
|
-
end
|
65
|
+
PgRls.const_set(const_name, PgRls.class_variable_get(var_name))
|
111
66
|
|
112
|
-
|
113
|
-
|
114
|
-
|
67
|
+
define_method(method_name) do
|
68
|
+
PgRls.const_get(const_name)
|
69
|
+
end
|
115
70
|
|
116
|
-
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
def admin_connection?
|
121
|
-
current_db_username != username
|
122
|
-
end
|
123
|
-
|
124
|
-
private
|
125
|
-
|
126
|
-
attr_writer :as_db_admin
|
127
|
-
|
128
|
-
def with_rls_connection(&)
|
129
|
-
reset_connection = admin_connection?
|
130
|
-
|
131
|
-
establish_new_connection! if reset_connection
|
132
|
-
ensure_block_execution(&)
|
133
|
-
ensure
|
134
|
-
establish_new_connection!(admin: true) if reset_connection
|
135
|
-
end
|
136
|
-
|
137
|
-
def establish_admin_connection
|
138
|
-
reset_rls_connection = false
|
139
|
-
current_tenant = nil
|
140
|
-
|
141
|
-
unless admin_connection?
|
142
|
-
reset_rls_connection = true
|
143
|
-
current_tenant = PgRls::Tenant.fetch
|
144
|
-
establish_new_connection!(admin: true)
|
71
|
+
PgRls.remove_class_variable(var_name)
|
72
|
+
end
|
145
73
|
end
|
146
|
-
|
147
|
-
[current_tenant, reset_rls_connection]
|
148
|
-
end
|
149
|
-
|
150
|
-
def ensure_block_execution(*, **)
|
151
|
-
yield(*, **).presence
|
152
|
-
end
|
153
|
-
|
154
|
-
def execute_query_or_block(query = nil, &)
|
155
|
-
return ensure_block_execution(&) if block_given?
|
156
|
-
|
157
|
-
execute(query)
|
158
|
-
end
|
159
|
-
|
160
|
-
def reset_connection_if_needed(current_tenant, reset_rls_connection)
|
161
|
-
return unless reset_rls_connection
|
162
|
-
|
163
|
-
establish_new_connection!
|
164
|
-
PgRls::Tenant.switch(current_tenant) if current_tenant.present?
|
165
74
|
end
|
75
|
+
# :nocov:
|
166
76
|
end
|
167
77
|
|
78
|
+
mattr_accessor :search_methods
|
79
|
+
@@search_methods = %i[subdomain tenant_id id]
|
80
|
+
|
168
81
|
mattr_accessor :table_name
|
169
|
-
@@table_name =
|
82
|
+
@@table_name = :organizations
|
170
83
|
|
171
84
|
mattr_accessor :class_name
|
172
|
-
@@class_name =
|
85
|
+
@@class_name = :Organization
|
173
86
|
|
174
87
|
mattr_accessor :username
|
175
|
-
@@username =
|
88
|
+
@@username = ENV.fetch("POSTGRES_RLS_USERNAME", "app_user")
|
176
89
|
|
177
90
|
mattr_accessor :password
|
178
|
-
@@password =
|
91
|
+
@@password = ENV.fetch("POSTGRES_RLS_PASSWORD", "password")
|
179
92
|
|
180
|
-
mattr_accessor :
|
181
|
-
@@
|
93
|
+
mattr_accessor :schema
|
94
|
+
@@schema = :public
|
182
95
|
|
183
|
-
mattr_accessor :
|
184
|
-
@@
|
96
|
+
mattr_accessor :rls_role_group
|
97
|
+
@@rls_role_group = :rls_group
|
98
|
+
|
99
|
+
mattr_accessor :connects_to
|
100
|
+
@@connects_to = nil
|
185
101
|
|
186
|
-
mattr_accessor :
|
187
|
-
@@
|
102
|
+
mattr_accessor :current_attributes
|
103
|
+
@@current_attributes = Array(nil)
|
188
104
|
|
189
|
-
mattr_accessor :
|
190
|
-
@@
|
105
|
+
mattr_accessor :abstract_base_record_class
|
106
|
+
@@abstract_base_record_class = "ActiveRecord::Base"
|
191
107
|
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
---
|
2
|
+
path: ".gem_rbs_collection"
|
3
|
+
gems:
|
4
|
+
- name: actionpack
|
5
|
+
version: '7.2'
|
6
|
+
source:
|
7
|
+
type: git
|
8
|
+
name: ruby/gem_rbs_collection
|
9
|
+
revision: 218cf130d31f63e110e350efc3fa265311b0f238
|
10
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
11
|
+
repo_dir: gems
|
12
|
+
- name: actionview
|
13
|
+
version: '6.0'
|
14
|
+
source:
|
15
|
+
type: git
|
16
|
+
name: ruby/gem_rbs_collection
|
17
|
+
revision: 218cf130d31f63e110e350efc3fa265311b0f238
|
18
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
19
|
+
repo_dir: gems
|
20
|
+
- name: activemodel
|
21
|
+
version: '7.0'
|
22
|
+
source:
|
23
|
+
type: git
|
24
|
+
name: ruby/gem_rbs_collection
|
25
|
+
revision: c718a9d97695937f952c72aec0c09632e1342201
|
26
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
27
|
+
repo_dir: gems
|
28
|
+
- name: activerecord
|
29
|
+
version: '7.2'
|
30
|
+
source:
|
31
|
+
type: git
|
32
|
+
name: ruby/gem_rbs_collection
|
33
|
+
revision: c718a9d97695937f952c72aec0c09632e1342201
|
34
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
35
|
+
repo_dir: gems
|
36
|
+
- name: activesupport
|
37
|
+
version: '7.0'
|
38
|
+
source:
|
39
|
+
type: git
|
40
|
+
name: ruby/gem_rbs_collection
|
41
|
+
revision: c718a9d97695937f952c72aec0c09632e1342201
|
42
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
43
|
+
repo_dir: gems
|
44
|
+
- name: concurrent-ruby
|
45
|
+
version: '1.1'
|
46
|
+
source:
|
47
|
+
type: git
|
48
|
+
name: ruby/gem_rbs_collection
|
49
|
+
revision: c718a9d97695937f952c72aec0c09632e1342201
|
50
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
51
|
+
repo_dir: gems
|
52
|
+
- name: date
|
53
|
+
version: '0'
|
54
|
+
source:
|
55
|
+
type: stdlib
|
56
|
+
- name: erb
|
57
|
+
version: '0'
|
58
|
+
source:
|
59
|
+
type: stdlib
|
60
|
+
- name: io-console
|
61
|
+
version: '0'
|
62
|
+
source:
|
63
|
+
type: stdlib
|
64
|
+
- name: logger
|
65
|
+
version: '0'
|
66
|
+
source:
|
67
|
+
type: stdlib
|
68
|
+
- name: monitor
|
69
|
+
version: '0'
|
70
|
+
source:
|
71
|
+
type: stdlib
|
72
|
+
- name: mutex_m
|
73
|
+
version: '0'
|
74
|
+
source:
|
75
|
+
type: stdlib
|
76
|
+
- name: nokogiri
|
77
|
+
version: '1.11'
|
78
|
+
source:
|
79
|
+
type: git
|
80
|
+
name: ruby/gem_rbs_collection
|
81
|
+
revision: 218cf130d31f63e110e350efc3fa265311b0f238
|
82
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
83
|
+
repo_dir: gems
|
84
|
+
- name: rails-dom-testing
|
85
|
+
version: '2.0'
|
86
|
+
source:
|
87
|
+
type: git
|
88
|
+
name: ruby/gem_rbs_collection
|
89
|
+
revision: 218cf130d31f63e110e350efc3fa265311b0f238
|
90
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
91
|
+
repo_dir: gems
|
92
|
+
- name: rails-html-sanitizer
|
93
|
+
version: '1.6'
|
94
|
+
source:
|
95
|
+
type: git
|
96
|
+
name: ruby/gem_rbs_collection
|
97
|
+
revision: 4af987b9b70455bd4493ef5a10e885f36e6ca6f6
|
98
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
99
|
+
repo_dir: gems
|
100
|
+
- name: railties
|
101
|
+
version: '6.0'
|
102
|
+
source:
|
103
|
+
type: git
|
104
|
+
name: ruby/gem_rbs_collection
|
105
|
+
revision: 218cf130d31f63e110e350efc3fa265311b0f238
|
106
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
107
|
+
repo_dir: gems
|
108
|
+
- name: securerandom
|
109
|
+
version: '0'
|
110
|
+
source:
|
111
|
+
type: stdlib
|
112
|
+
- name: singleton
|
113
|
+
version: '0'
|
114
|
+
source:
|
115
|
+
type: stdlib
|
116
|
+
- name: thor
|
117
|
+
version: '1.2'
|
118
|
+
source:
|
119
|
+
type: git
|
120
|
+
name: ruby/gem_rbs_collection
|
121
|
+
revision: 218cf130d31f63e110e350efc3fa265311b0f238
|
122
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
123
|
+
repo_dir: gems
|
124
|
+
- name: time
|
125
|
+
version: '0'
|
126
|
+
source:
|
127
|
+
type: stdlib
|
128
|
+
- name: tsort
|
129
|
+
version: '0'
|
130
|
+
source:
|
131
|
+
type: stdlib
|
132
|
+
gemfile_lock_path: Gemfile.lock
|
data/rbs_collection.yaml
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# Download sources
|
2
|
+
sources:
|
3
|
+
- type: git
|
4
|
+
name: ruby/gem_rbs_collection
|
5
|
+
remote: https://github.com/ruby/gem_rbs_collection.git
|
6
|
+
revision: main
|
7
|
+
repo_dir: gems
|
8
|
+
|
9
|
+
# You can specify local directories as sources also.
|
10
|
+
# - type: local
|
11
|
+
# path: path/to/your/local/repository
|
12
|
+
|
13
|
+
# A directory to install the downloaded RBSs
|
14
|
+
path: .gem_rbs_collection
|
15
|
+
gems:
|
16
|
+
- name: activemodel
|
17
|
+
- name: activerecord
|
18
|
+
- name: activesupport
|
19
|
+
- name: concurrent-ruby
|
20
|
+
|
21
|
+
- name: ffi
|
22
|
+
ignore: true
|
23
|
+
|
24
|
+
- name: ast
|
25
|
+
ignore: true
|
26
|
+
|
27
|
+
- name: base64
|
28
|
+
ignore: true
|
29
|
+
|
30
|
+
- name: bigdecimal
|
31
|
+
ignore: true
|
32
|
+
|
33
|
+
- name: cgi
|
34
|
+
ignore: true
|
35
|
+
|
36
|
+
- name: connection_pool
|
37
|
+
ignore: true
|
38
|
+
|
39
|
+
- name: csv
|
40
|
+
ignore: true
|
41
|
+
|
42
|
+
- name: date
|
43
|
+
ignore: true
|
44
|
+
|
45
|
+
- name: diff-lcs
|
46
|
+
ignore: true
|
47
|
+
|
48
|
+
- name: erb
|
49
|
+
ignore: true
|
50
|
+
|
51
|
+
- name: fileutils
|
52
|
+
ignore: true
|
53
|
+
|
54
|
+
- name: forwardable
|
55
|
+
ignore: true
|
56
|
+
|
57
|
+
- name: i18n
|
58
|
+
ignore: true
|
59
|
+
|
60
|
+
- name: json
|
61
|
+
ignore: true
|
62
|
+
|
63
|
+
- name: listen
|
64
|
+
ignore: true
|
65
|
+
|
66
|
+
- name: logger
|
67
|
+
ignore: true
|
68
|
+
|
69
|
+
- name: minitest
|
70
|
+
ignore: true
|
71
|
+
|
72
|
+
- name: monitor
|
73
|
+
ignore: true
|
74
|
+
|
75
|
+
- name: mutex_m
|
76
|
+
ignore: true
|
77
|
+
|
78
|
+
- name: optparse
|
79
|
+
ignore: true
|
80
|
+
|
81
|
+
- name: parser
|
82
|
+
ignore: true
|
83
|
+
|
84
|
+
- name: pathname
|
85
|
+
ignore: true
|
86
|
+
|
87
|
+
- name: rack
|
88
|
+
ignore: true
|
89
|
+
|
90
|
+
- name: rainbow
|
91
|
+
ignore: true
|
92
|
+
|
93
|
+
- name: rake
|
94
|
+
ignore: true
|
95
|
+
|
96
|
+
- name: rbs
|
97
|
+
ignore: true
|
98
|
+
|
99
|
+
- name: rdoc
|
100
|
+
ignore: true
|
101
|
+
|
102
|
+
- name: securerandom
|
103
|
+
ignore: true
|
104
|
+
|
105
|
+
- name: singleton
|
106
|
+
ignore: true
|
107
|
+
|
108
|
+
- name: strscan
|
109
|
+
ignore: true
|
110
|
+
|
111
|
+
- name: tempfile
|
112
|
+
ignore: true
|
113
|
+
|
114
|
+
- name: time
|
115
|
+
ignore: true
|
116
|
+
|
117
|
+
- name: timeout
|
118
|
+
ignore: true
|
119
|
+
|
120
|
+
- name: tsort
|
121
|
+
ignore: true
|
122
|
+
|
123
|
+
- name: tzinfo
|
124
|
+
ignore: true
|
125
|
+
|
126
|
+
- name: uri
|
127
|
+
ignore: true
|
data/review_code.sh
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
GREEN='\033[0;32m'
|
4
|
+
RED='\033[0;31m'
|
5
|
+
YELLOW='\033[0;33m'
|
6
|
+
NC='\033[0m' # No Color
|
7
|
+
|
8
|
+
echo -e "${YELLOW}Running Rubocop...${NC}"
|
9
|
+
bin/rubocop
|
10
|
+
if [ $? -eq 0 ]; then
|
11
|
+
echo -e "${GREEN}Rubocop passed!${NC}"
|
12
|
+
else
|
13
|
+
echo -e "${RED}Rubocop failed!${NC}"
|
14
|
+
exit 1
|
15
|
+
fi
|
16
|
+
|
17
|
+
echo -e "${YELLOW}Running Steep...${NC}"
|
18
|
+
bin/steep
|
19
|
+
if [ $? -eq 0 ]; then
|
20
|
+
echo -e "${GREEN}Steep passed!${NC}"
|
21
|
+
else
|
22
|
+
echo -e "${RED}Steep failed!${NC}"
|
23
|
+
exit 1
|
24
|
+
fi
|
25
|
+
|
26
|
+
echo -e "${YELLOW}Running tests...${NC}"
|
27
|
+
bin/test
|
28
|
+
if [ $? -eq 0 ]; then
|
29
|
+
echo -e "${GREEN}Tests passed!${NC}"
|
30
|
+
else
|
31
|
+
echo -e "${RED}Tests failed!${NC}"
|
32
|
+
exit 1
|
33
|
+
fi
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PgRls
|
4
|
+
module Generators
|
5
|
+
class ActiveRecordGenerator < ::ActiveRecord::Generators::ModelGenerator
|
6
|
+
def check_class_collision: () -> void
|
7
|
+
|
8
|
+
def create_model_file: () -> void
|
9
|
+
|
10
|
+
def upgrade_model_file: () -> void
|
11
|
+
|
12
|
+
def create_migration_file: () -> void
|
13
|
+
|
14
|
+
def upgrade_migration_file: () -> void
|
15
|
+
|
16
|
+
def backport_migration_file: () -> void
|
17
|
+
|
18
|
+
def template: (String, String, **untyped) -> void
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def installing?: () -> bool
|
23
|
+
|
24
|
+
def migration_template_prefix: () -> String
|
25
|
+
|
26
|
+
def generate_abstract_class: () -> void
|
27
|
+
|
28
|
+
def model_path: () -> String
|
29
|
+
|
30
|
+
def generate_abstract_class_path: () -> String
|
31
|
+
|
32
|
+
def class_coalescing?: () -> bool
|
33
|
+
|
34
|
+
def clean_indexes_attributes!: () -> void
|
35
|
+
|
36
|
+
def model_file_exists?: () -> bool
|
37
|
+
|
38
|
+
def parent_class_name: () -> String
|
39
|
+
|
40
|
+
def rls_parent: () -> String
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PgRls
|
4
|
+
# Generator to install the gem
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
attr_reader attributes: :untyped
|
7
|
+
|
8
|
+
def initialize: (untyped, *untyped) -> void
|
9
|
+
|
10
|
+
def create_install_config: () -> void
|
11
|
+
|
12
|
+
def show_readme: () -> void
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def pg_rls_config: (String) -> void
|
17
|
+
|
18
|
+
def invoke?: () -> bool
|
19
|
+
end
|
20
|
+
end
|