rhino_project_core 0.20.0.alpha.0 → 0.20.0.beta.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +4 -5
  3. data/app/controllers/concerns/rhino/error_handling.rb +0 -2
  4. data/app/controllers/rhino/simple_controller.rb +1 -3
  5. data/app/overrides/devise_token_auth/omniauth_callbacks_controller_override.rb +2 -2
  6. data/app/overrides/devise_token_auth/registrations_controller_override.rb +1 -1
  7. data/lib/commands/rhino_command.rb +59 -0
  8. data/lib/generators/rhino/dev/setup/setup_generator.rb +31 -55
  9. data/lib/generators/rhino/module/module_generator.rb +59 -58
  10. data/lib/generators/rhino/module/templates/engine.rb.tt +19 -0
  11. data/lib/generators/rhino/module/templates/{lib/generators/%namespaced_name%/install/install_generator.rb.tt → install_generator.rb.tt} +1 -1
  12. data/lib/generators/rhino/module/templates/module_tasks.rake.tt +17 -0
  13. data/lib/rhino/engine.rb +14 -40
  14. data/lib/rhino/resource/active_model_extension/properties.rb +0 -2
  15. data/lib/rhino/resource/active_record_extension/properties.rb +1 -1
  16. data/lib/rhino/resource/active_record_extension/properties_describe.rb +0 -2
  17. data/lib/rhino/resource/active_record_extension.rb +0 -2
  18. data/lib/rhino/resource/properties.rb +2 -2
  19. data/lib/rhino/resource/reference.rb +2 -0
  20. data/lib/rhino/resource.rb +1 -2
  21. data/lib/rhino/sieve.rb +0 -1
  22. data/lib/rhino/test_case/controller.rb +9 -20
  23. data/lib/rhino/test_case.rb +0 -1
  24. data/lib/rhino/version.rb +1 -1
  25. data/lib/{rhino_project_core.rb → rhino.rb} +0 -2
  26. data/lib/tasks/rhino.rake +14 -0
  27. metadata +19 -372
  28. data/LICENSE +0 -21
  29. data/lib/commands/rhino/module/coverage_command.rb +0 -44
  30. data/lib/commands/rhino/module/dummy_command.rb +0 -43
  31. data/lib/commands/rhino/module/new_command.rb +0 -34
  32. data/lib/commands/rhino/module/rails_command.rb +0 -43
  33. data/lib/commands/rhino/module/test_command.rb +0 -43
  34. data/lib/generators/rhino/dev/setup/templates/env.root.tt +0 -1
  35. data/lib/generators/rhino/model/model_generator.rb +0 -96
  36. data/lib/generators/rhino/module/USAGE +0 -6
  37. data/lib/generators/rhino/module/templates/%name%.gemspec.tt +0 -24
  38. data/lib/generators/rhino/module/templates/lib/%namespaced_name%/engine.rb.tt +0 -18
  39. data/lib/generators/rhino/module/templates/lib/tasks/%namespaced_name%_tasks.rake.tt +0 -13
  40. data/lib/generators/rhino/module/templates/test/dummy/app/models/user.rb +0 -4
  41. data/lib/generators/rhino/module/templates/test/dummy/config/database.yml +0 -25
  42. data/lib/generators/rhino/module/templates/test/dummy/config/initializers/devise.rb +0 -311
  43. data/lib/generators/rhino/module/templates/test/dummy/config/initializers/devise_token_auth.rb +0 -71
  44. data/lib/generators/rhino/module/templates/test/test_helper.rb +0 -54
  45. data/lib/rhino/resource/active_record_extension/super_admin.rb +0 -25
  46. data/lib/rhino/sieve/geospatial.rb +0 -45
  47. data/lib/rhino/test_case/model.rb +0 -86
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f2e6d0cf9a761ebe9b75b3cacf2b6345a2b91df4d9d3f456a9108492aac0988
4
- data.tar.gz: 45365e2f7d1efe25bbfc153a497804758a43bc160c2d13a22918af94390d0790
3
+ metadata.gz: f8779f64179f5c2a26ea37d704c7ac7355f713fc2f386aa6ab08e3e7a0ff174f
4
+ data.tar.gz: 2e6139b4b62758822ab9db651b9468af7726e0a56d0a34c1d5712b418e21db70
5
5
  SHA512:
6
- metadata.gz: bdb873a1c1e4717d74dc52dda547b573a921e730023fa6ea307a2df0b776fd579832aba12da869d1c33e2edc2d2a39f7a5bc33a501e177ccb7cf0db71c7d6908
7
- data.tar.gz: 7375ef91e536a7a77b1a39e85ee5c501b035b6bd4127ad824064424ef78ae64b6114600dd88c6eade02ce7350fa1a3ffe5787a80ac07db4e625cf823c90c5444
6
+ metadata.gz: 877bcedc2608beaa6d9d667991858d1b3c272ff876380e1ec1c34e07504cfbc79b153f686aafecc47b8f233d7939c8310012ec99c9f160ff30bc36543d079efb
7
+ data.tar.gz: 3a63eab50a46bbfc236d1cc8d4e0f123bf908ae2a94fbaaf2e251c00817daff159c4acc0a4400730e7cb2df0c39b347595cbac6f810e7aa81c74bfa228d74a56
data/Rakefile CHANGED
@@ -25,11 +25,10 @@ require 'bundler/gem_tasks'
25
25
 
26
26
  require 'rake/testtask'
27
27
 
28
- Rake::TestTask.new do |t|
29
- t.libs << "test"
30
- t.test_files = FileList["test/**/*_test.rb"].exclude("test/system/**/*", "test/dummy/**/*")
31
- t.verbose = true
32
- t.warning = false
28
+ Rake::TestTask.new(:test) do |t|
29
+ t.libs << 'test'
30
+ t.pattern = 'test/**/*_test.rb'
31
+ t.verbose = false
33
32
  end
34
33
 
35
34
  task default: :test
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_record/associations"
4
-
5
3
  module Rhino
6
4
  module ErrorHandling
7
5
  extend ActiveSupport::Concern
@@ -5,9 +5,7 @@ module Rhino
5
5
  def action_missing(action)
6
6
  authorize klass, "#{action}?".to_sym
7
7
 
8
- method = klass.method(action)
9
-
10
- render json: method.parameters.any? ? klass.send(action, params) : klass.send(action)
8
+ render json: klass.send(action)
11
9
  end
12
10
  end
13
11
  end
@@ -3,7 +3,7 @@
3
3
  # https://stackoverflow.com/questions/4470108/when-monkey-patching-an-instance-method-can-you-call-the-overridden-method-from/4471202
4
4
  # Mixin Prepending
5
5
  module DeviseTokenAuth::OmniauthCallbacksController::Extensions
6
- include RhinoOrganizations::Concerns::CreateOrganization if Rhino.resources.include?("Organization")
6
+ include RhinoOrganizations::Concerns::CreateOrganization
7
7
 
8
8
  def redirect_callbacks
9
9
  # derive target redirect route from 'resource_class' param, which was set
@@ -30,7 +30,7 @@ module DeviseTokenAuth::OmniauthCallbacksController::Extensions
30
30
 
31
31
  # set a server cookie if configured
32
32
  if DeviseTokenAuth.cookie_enabled
33
- auth_header = @resource.build_auth_headers(@token.token, @token.client)
33
+ auth_header = @resource.build_auth_header(@token.token, @token.client)
34
34
  cookies[DeviseTokenAuth.cookie_name] = DeviseTokenAuth.cookie_attributes.merge(value: auth_header.to_json)
35
35
  end
36
36
  rescue ActiveRecord::RecordInvalid
@@ -3,7 +3,7 @@
3
3
  # https://stackoverflow.com/questions/4470108/when-monkey-patching-an-instance-method-can-you-call-the-overridden-method-from/4471202
4
4
  # Mixin Prepending
5
5
  module DeviseTokenAuth::RegistrationsController::Extensions
6
- include RhinoOrganizations::Concerns::CreateOrganization if Rhino.resources.include?("Organization")
6
+ include RhinoOrganizations::Concerns::CreateOrganization
7
7
 
8
8
  def create
9
9
  return render_error(401, "signup is not allowed") unless Rhino.allow_signup
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dotenv"
4
+ require "rails/command"
5
+
6
+ module Rails
7
+ module Command
8
+ class RhinoCommand < Base # :nodoc:
9
+ include Thor::Actions
10
+
11
+ no_commands do
12
+ def help
13
+ say "rails rhino::dummy [module] command # Run rails command in dummy application, defaults to rhino"
14
+ end
15
+ end
16
+
17
+ def dummy(*args)
18
+ rhino_command("test/dummy", nil, *args)
19
+ end
20
+
21
+ def test(*args)
22
+ rhino_command(nil, "test", *args)
23
+ end
24
+
25
+ def rails(*args)
26
+ rhino_command(nil, nil, *args)
27
+ end
28
+
29
+ def coverage(*args)
30
+ ENV["COVERAGE"] = "1"
31
+ test(*args)
32
+ end
33
+
34
+ protected
35
+ def rhino_command(extra_path, base_command, *args) # rubocop:todo Metrics/MethodLength
36
+ # Default to just rhino/rhino if no obvious module
37
+ module_name = if Dir.exist?("rhino/rhino_#{args[0]}")
38
+ args.shift
39
+ else
40
+ nil
41
+ end
42
+ module_base = ["rhino", module_name].compact.join("_")
43
+ module_path = ["rhino/#{module_base}", extra_path].compact.join("/")
44
+ db_name = "#{module_base}_dummy"
45
+
46
+ # Getting existing variables and re-use
47
+ ::Dotenv.load
48
+
49
+ inside(module_path) do
50
+ # Override DB_NAME so multiple can run in parallel
51
+ run(
52
+ "DB_NAME=#{db_name} BUNDLE_GEMFILE='#{__dir__}/../../../../Gemfile' bin/rails #{base_command} #{args.join(' ')}",
53
+ { abort_on_failure: true }
54
+ )
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -5,21 +5,16 @@ module Rhino
5
5
  module Dev
6
6
  # rubocop:disable Metrics/ClassLength
7
7
  class SetupGenerator < ::Rails::Generators::Base
8
- DEFAULT_SERVER_PORT = 3000
9
- DEFAULT_CLIENT_PORT = DEFAULT_SERVER_PORT + 1
10
-
11
- class_option :prompt, type: :boolean, default: true, desc: "Prompt user for configuration options"
12
- class_option :defaults, type: :string, enum: %w[local docker], default: "local", desc: "Use configuration defaults of type DEFAULTS"
13
- class_option :skip_existing, type: :boolean, default: false, desc: "Skip existing env files"
14
- class_option :server_port, type: :numeric, default: DEFAULT_SERVER_PORT, group: :server, desc: "Server port"
15
- class_option :client_port, type: :numeric, default: DEFAULT_CLIENT_PORT, group: :client, desc: "Client port"
16
- class_option :db_host, type: :string, group: :database
17
- class_option :db_name, type: :string, group: :database
18
- class_option :db_port, type: :numeric, default: 5432, group: :database
19
- class_option :db_user, type: :string, group: :database
20
- class_option :db_password, type: :string, group: :database
21
- class_option :redis_port, type: :numeric, default: 6379, group: :redis
22
- class_option :redis_database, type: :numeric, default: 0, group: :redis
8
+ class_option :prompt, type: :boolean, default: true
9
+ class_option :server_port, type: :numeric
10
+ class_option :client_port, type: :numeric
11
+ class_option :db_host, type: :string
12
+ class_option :db_name, type: :string
13
+ class_option :db_port, type: :numeric
14
+ class_option :db_user, type: :string
15
+ class_option :db_password, type: :string
16
+ class_option :redis_port, type: :numeric
17
+ class_option :redis_database, type: :numeric
23
18
 
24
19
  attr_reader :server_port,
25
20
  :client_port,
@@ -35,19 +30,11 @@ module Rhino
35
30
 
36
31
  source_root File.expand_path("templates", __dir__)
37
32
 
38
- def check_existing
39
- return unless options[:skip_existing] && File.exist?(server_file(".env"))
40
-
41
- say "Skipping existing .env files"
42
- exit(0)
43
- end
44
-
45
33
  def setup_env
46
34
  say "Setting up local .env files"
47
35
 
48
36
  collect_env_info
49
37
 
50
- template "env.root", project_file(".env")
51
38
  template "env.server", server_file(".env")
52
39
  template "env.client", client_file(".env")
53
40
  end
@@ -71,19 +58,17 @@ module Rhino
71
58
  end
72
59
 
73
60
  def server_port_default
74
- options[:server_port] || ENV["PORT"]
61
+ options[:server_port] || ENV["PORT"] || 3000
75
62
  end
76
63
 
77
64
  def client_port_default
78
65
  @server_port.to_i + 1
79
66
  end
80
67
 
81
- def project_name
82
- @project_name ||= File.basename(project_dir).sub(/[-_]?mono/, "")
83
- end
84
-
85
68
  def db_name_default
86
- db_name = options[:db_name] || ENV["DB_NAME"] || project_name
69
+ db_name =
70
+ options[:db_name] || ENV["DB_NAME"] ||
71
+ File.basename(project_dir).sub(/[-_]?mono/, "")
87
72
 
88
73
  return db_name if db_name.present?
89
74
 
@@ -95,15 +80,15 @@ module Rhino
95
80
  end
96
81
 
97
82
  def db_port_default
98
- options[:db_port] || ENV["DB_PORT"]
83
+ options[:db_port] || ENV["DB_PORT"] || 5432
99
84
  end
100
85
 
101
86
  def db_user_default
102
- options[:db_user] || ENV["DB_USERNAME"] || `whoami`
87
+ options[:db_user] || ENV["DB_USERNAME"] || (dockerized ? "postgres" : "")
103
88
  end
104
89
 
105
90
  def db_password_default
106
- options[:db_password] || ENV["DB_PASSWORD"] || ""
91
+ options[:db_password] || ENV["DB_PASSWORD"] || (dockerized ? "password" : "")
107
92
  end
108
93
 
109
94
  def redis_host_default
@@ -111,15 +96,15 @@ module Rhino
111
96
  end
112
97
 
113
98
  def redis_port_default
114
- options[:redis_port] || ENV["REDIS_PORT"]
99
+ options[:redis_port] || ENV["REDIS_PORT"] || 6379
115
100
  end
116
101
 
117
102
  def redis_database_default
118
- options[:redis_database] || ENV["REDIS_DATABASE"]
103
+ options[:redis_database] || ENV["REDIS_DATABASE"] || 0
119
104
  end
120
105
 
121
106
  def dockerized_default
122
- options[:defaults] == "docker" ? "Y" : "N"
107
+ "yN"
123
108
  end
124
109
 
125
110
  def collect_env_info
@@ -133,46 +118,37 @@ module Rhino
133
118
  end
134
119
 
135
120
  def collect_docker_info
136
- @dockerized = %w[y Y].include?(ask_prompt("Run with docker?", dockerized_default))
121
+ @dockerized = %w[y Y].include?(ask_prompt("Run server on docker?", dockerized_default))
137
122
 
138
123
  return unless dockerized
139
124
 
140
125
  @db_host = "db"
141
- @db_user = "postgres"
142
- @db_password = "password"
143
- @db_port = 5432
144
126
  @redis_host = "redis"
145
127
  @redis_port = 6379
146
- @redis_database = 0
147
128
 
148
129
  puts <<~HERE
149
130
  The following docker configuration has been automatically set for you:
150
131
  Database host: #{db_host}
151
- Database port: #{db_port}
152
- Database user: #{db_user}
153
- Database password: #{db_password}
154
132
  Redis host: #{redis_host}
155
133
  Redis port: #{redis_port}
156
- Redis database: #{redis_database}
157
134
  HERE
158
135
  end
159
136
 
160
- def collect_database_info
137
+ def collect_database_info # rubocop:todo Metrics/AbcSize
161
138
  @db_name = ask_prompt("Database?", db_name_default)
162
- @db_host ||= ask_prompt("Database host?", db_host_default)
163
- @db_port ||= ask_prompt("Database port?", db_port_default)
164
- @db_user ||= ask_prompt("Database User?", db_user_default)
165
- @db_password ||= ask_prompt("Database Password?", db_password_default)
166
-
167
- nil
139
+ @db_host = ask_prompt("Database host?", db_host_default) unless dockerized
140
+ @db_port = ask_prompt("Database port?", db_port_default)
141
+ @db_user = ask_prompt("Database User?", db_user_default) until !dockerized || db_user.present?
142
+ @db_password = ask_prompt("Database Password?", db_password_default) until !dockerized || db_password.present?
168
143
  end
169
144
 
170
145
  def collect_redis_info
171
- @redis_host ||= ask_prompt("Redis host?", redis_host_default)
172
- @redis_port ||= ask_prompt("Redis port?", redis_port_default)
173
- @redis_database ||= ask_prompt("Redis database?", redis_database_default)
146
+ unless dockerized
147
+ @redis_host = ask_prompt("Redis host?", redis_host_default)
148
+ @redis_port = ask_prompt("Redis port?", redis_port_default)
149
+ end
174
150
 
175
- nil
151
+ @redis_database = ask_prompt("Redis database?", redis_database_default)
176
152
  end
177
153
 
178
154
  def project_file(file)
@@ -1,90 +1,91 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rails/generators"
4
- require "rails/generators/rails/plugin/plugin_generator"
5
- require "rhino/version"
6
-
7
3
  module Rhino
8
4
  module Generators
9
- class ModuleBuilder < ::Rails::PluginBuilder
10
- def lib
11
- template "lib/%namespaced_name%.rb"
12
- template "lib/%namespaced_name%/version.rb"
5
+ class ModuleGenerator < ::Rails::Generators::Base
6
+ attr_reader :module_name, :module_path
13
7
 
14
- template "lib/%namespaced_name%/engine.rb"
8
+ class_option :full, type: :boolean, default: false,
9
+ desc: 'Full plugin generation'
15
10
 
16
- # The install generator
17
- empty_directory_with_keep_file "lib/generators/#{namespaced_name}/install/templates"
18
- template "lib/generators/%namespaced_name%/install/install_generator.rb"
19
- template "lib/tasks/%namespaced_name%_tasks.rake"
20
- end
11
+ class_option :skip_plugin, type: :boolean, default: false,
12
+ desc: 'Skip plugin generation'
21
13
 
22
- # FIXME: Hack because the engine.rb file is over aggressive in its checks
23
- def rhino_hack
24
- template "test/dummy/config/initializers/devise.rb"
25
- template "test/dummy/config/initializers/devise_token_auth.rb"
26
- template "test/dummy/app/models/user.rb"
27
- remove_file "test/dummy/config/database.yml"
28
- template "test/dummy/config/database.yml"
29
- end
30
- end
14
+ source_root File.expand_path('templates', __dir__)
15
+
16
+ def create_module
17
+ @module_name = ask('Module name?')
18
+ @module_name = "rhino_#{module_name}" unless module_name.starts_with?('rhino_')
19
+ @module_path = "rhino/#{module_name}"
31
20
 
32
- class ModuleGenerator < ::Rails::Generators::PluginGenerator
33
- source_root File.expand_path("templates", __dir__)
21
+ return if options[:skip_plugin]
34
22
 
35
- class_option :database, type: :string, aliases: "-d", default: "postgresql", hide: true
36
- class_option :full, type: :boolean, default: true, hide: true
37
- remove_class_option :template
23
+ say "Creating #{module_name}"
38
24
 
39
- def self.banner
40
- "rails rhino:module #{arguments.map(&:usage).join(' ')} [options]"
25
+ plugin_command = "plugin new #{module_path} --skip-git"
26
+ plugin_command = "#{plugin_command} --full" if options[:full]
27
+ rails_command(plugin_command)
41
28
  end
42
29
 
43
- # Parent source paths
44
- def source_paths
45
- [
46
- File.expand_path("templates", __dir__),
47
- Rails::Generators::PluginGenerator.source_root
48
- ]
30
+ def remove_license
31
+ remove_file "#{module_path}/MIT-LICENSE"
49
32
  end
50
33
 
51
- # Has to be named this way as it overrides the default
52
- def get_builder_class # rubocop:disable Naming/AccessorMethodName
53
- ModuleBuilder
34
+ def engine_registration
35
+ engine_file = "#{module_path}/lib/#{module_name}/engine.rb"
36
+
37
+ remove_file engine_file
38
+ template 'engine.rb', engine_file
54
39
  end
55
40
 
56
- def engine_config
57
- content = []
41
+ def create_install_generator
42
+ generator_path = "#{module_path}/lib/generators/#{module_name}/install"
43
+ tasks_path = "#{module_path}/lib/tasks"
58
44
 
59
- content << "isolate_namespace #{camelized_modules}\n" if mountable?
60
- content << "config.generators.api_only = true" if api?
45
+ empty_directory "#{generator_path}/templates"
46
+ create_file("#{generator_path}/templates/.keep")
61
47
 
62
- return optimize_indentation(content.join("\n"), 4) if content.any?
48
+ template 'install_generator.rb', "#{generator_path}/install_generator.rb"
49
+ template 'module_tasks.rake', "#{tasks_path}/#{module_name}.rake"
63
50
 
64
- nil
51
+ remove_file "#{tasks_path}/#{module_name}_tasks.rake"
65
52
  end
66
53
 
67
- def rhino_version
68
- ::Rhino::VERSION::STRING
54
+ def fix_gemspec
55
+ gemspec_file = "#{module_path}/#{module_name}.gemspec"
56
+
57
+ gsub_file gemspec_file, /spec.homepage.*/, 'spec.homepage = ""'
58
+ gsub_file gemspec_file, /spec.summary.*/, 'spec.summary = ""'
59
+ gsub_file gemspec_file, /spec.description.*/, 'spec.description = ""'
60
+ gsub_file gemspec_file, /spec.license.*/, 'spec.license = ""'
61
+ gsub_file gemspec_file, 'spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]', 'spec.files = Dir["{app,config,db,lib}/**/*", "Rakefile", "README.md"]' # rubocop:disable Layout/LineLength
69
62
  end
70
63
 
71
- def rhino_setup
72
- return unless with_dummy_app?
64
+ # Gross hack for now
65
+ DUMMY_SETUP_FILES = [
66
+ 'config/database.yml',
67
+ 'config/initializers/devise_token_auth.rb',
68
+ 'config/initializers/devise.rb',
69
+ 'app/models/user.rb',
70
+ 'db/migrate/20210111014230_devise_token_auth_create_users.rhino_engine.rb'
71
+ ].freeze
72
+
73
+ def dummy_setup
74
+ return unless options[:full]
73
75
 
74
- build(:rhino_hack)
76
+ rhino_dummy = Rails.root.join('rhino/rhino/test/dummy')
77
+ module_dummy = Rails.root.join("#{module_path}/test/dummy")
75
78
 
76
- inside(rails_app_path) do
77
- run "rails rhino:module:dummy #{namespaced_name} rhino:install"
78
- run "rails rhino:module:dummy #{namespaced_name} db:create"
79
- run "rails rhino:module:dummy #{namespaced_name} db:migrate"
79
+ remove_file "#{module_dummy}/config/database.yml"
80
+
81
+ DUMMY_SETUP_FILES.each do |file|
82
+ copy_file "#{rhino_dummy}/#{file}", "#{module_dummy}/#{file}"
80
83
  end
81
84
  end
82
85
 
83
86
  def rubocop
84
- template ".rubocop.yml"
85
-
86
- inside(File.join(rails_app_path, namespaced_name)) do
87
- run "bundle exec rubocop -A ", capture: true
87
+ inside(module_path) do
88
+ run 'bundle exec rubocop -a', capture: true
88
89
  end
89
90
  end
90
91
  end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rhino/engine"
4
+
5
+ module <%= module_name.camelize %>
6
+ class Engine < ::Rails::Engine
7
+ config.autoload_paths << File.expand_path("../../lib", __dir__)
8
+
9
+ initializer "<%= module_name %>.register_module" do
10
+ config.after_initialize do
11
+ if true
12
+ Rhino.registered_modules[:<%= module_name %>] = {
13
+ version: <%= module_name.camelize %>::VERSION
14
+ }
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module <%= camelized_modules %>
3
+ module <%= module_name.camelize %>
4
4
  module Generators
5
5
  class InstallGenerator < ::Rails::Generators::Base
6
6
  source_root File.expand_path("templates", __dir__)
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :<%= module_name %> do
4
+ # Prevent migration installation task from showing up twice.
5
+ if Rake::Task.task_defined?("<%= module_name %>_engine:install:migrations")
6
+ Rake::Task["<%= module_name %>_engine:install:migrations"].clear_comments
7
+ end
8
+
9
+ desc "Install <%= module_name %>"
10
+ task install: :environment do
11
+ if Rake::Task.task_defined?("<%= module_name %>_engine:install:migrations")
12
+ Rake::Task["<%= module_name %>_engine:install:migrations"].invoke
13
+ end
14
+
15
+ Rails::Command.invoke :generate, ["<%= module_name %>:install"]
16
+ end
17
+ end
data/lib/rhino/engine.rb CHANGED
@@ -1,31 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rhino/version"
4
-
5
- # https://guides.rubyonrails.org/engines.html#other-gem-dependencies
6
- require "activeadmin"
7
- require "acts-as-taggable-on"
8
- require "ancestry"
9
- require "arel-helpers"
10
- require "countries"
11
- require "devise"
12
- require "devise_invitable"
13
- require "devise_token_auth"
14
- require "friendly_id"
15
- require "geocoder"
16
- require "omniauth"
17
- require "omniauth-azure-activedirectory-v2"
18
- require "omniauth-auth0"
19
- require "omniauth-facebook"
20
- require "omniauth-github"
21
- require "omniauth-google-oauth2"
22
- require "omniauth/rails_csrf_protection"
23
- require "rack/cors"
24
- require "pg_search"
25
- require "phonelib"
26
- require "pundit"
27
- require "segment/analytics"
28
-
29
3
  module Rhino
30
4
  class Engine < ::Rails::Engine
31
5
  config.before_configuration do
@@ -37,19 +11,19 @@ module Rhino
37
11
  end
38
12
  end
39
13
 
40
- initializer "rhino.active_record_extension" do
14
+ initializer 'rhino.active_record_extension' do
41
15
  ActiveSupport.on_load(:active_record) do
42
- require_relative "resource/active_record_extension"
43
- require_relative "resource/active_record_tree"
44
- require_relative "resource/active_model_extension"
16
+ require_relative 'resource/active_record_extension'
17
+ require_relative 'resource/active_record_tree'
18
+ require_relative 'resource/active_model_extension'
45
19
 
46
20
  include Rhino::Resource::ActiveRecordExtension if Rhino.auto_include_active_record
47
21
  end
48
22
  end
49
23
 
50
- initializer "rhino.active_storage_extension" do
24
+ initializer 'rhino.active_storage_extension' do
51
25
  ActiveSupport.on_load(:active_storage_attachment) do
52
- require_relative "resource/active_storage_extension"
26
+ require_relative 'resource/active_storage_extension'
53
27
 
54
28
  include Rhino::Resource::ActiveStorageExtension
55
29
  end
@@ -57,7 +31,7 @@ module Rhino
57
31
 
58
32
  # https://guides.rubyonrails.org/engines.html#overriding-models-and-controllers
59
33
  # Use root instead of Rails.root to scope for this engine
60
- initializer "rhino.overrides" do
34
+ initializer 'rhino.overrides' do
61
35
  overrides = "#{root}/app/overrides"
62
36
  Rails.autoloaders.main.ignore(overrides)
63
37
 
@@ -68,13 +42,13 @@ module Rhino
68
42
  end
69
43
  end
70
44
 
71
- initializer "rhino.check_resources" do
45
+ initializer 'rhino.check_resources' do
72
46
  config.after_initialize do
73
47
  check_resources
74
48
  end
75
49
  end
76
50
 
77
- initializer "rhino.resource_reloader" do
51
+ initializer 'rhino.resource_reloader' do
78
52
  config.after_initialize do
79
53
  Rails.application.reloader.to_prepare do
80
54
  Rhino.resource_classes = nil
@@ -82,12 +56,12 @@ module Rhino
82
56
  end
83
57
  end
84
58
 
85
- initializer "rhino.register_module" do
86
- require "rhino/omniauth/strategies/azure_o_auth2"
59
+ initializer 'rhino.register_module' do
60
+ require 'rhino/omniauth/strategies/azure_o_auth2'
87
61
 
88
62
  config.after_initialize do
89
63
  Rhino.registered_modules[:rhino] = {
90
- version: Rhino::VERSION::STRING,
64
+ version: Rhino::VERSION,
91
65
  authOwner: Rhino.auth_owner.model_name.singular,
92
66
  baseOwner: Rhino.base_owner.model_name.singular,
93
67
  oauth: Rhino::OmniauthHelper.strategies_metadata,
@@ -156,11 +130,11 @@ module Rhino
156
130
  end
157
131
 
158
132
  def self.run_from_dev_setup?
159
- defined?(Rake.application) && Rake.application.top_level_tasks == ["rhino:dev:setup"]
133
+ Rake.application.top_level_tasks == ["rhino:dev:setup"]
160
134
  end
161
135
 
162
136
  def self.run_from_package?
163
- defined?(Rake.application) && Rake.application.top_level_tasks == ["package"]
137
+ Rake.application.top_level_tasks == ["package"]
164
138
  end
165
139
  end
166
140
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "js_regex"
4
-
5
3
  module Rhino
6
4
  module Resource
7
5
  module ActiveModelExtension
@@ -44,7 +44,7 @@ module Rhino
44
44
  end
45
45
 
46
46
  def virtual_properties
47
- columns.select(&:virtual?).map(&:name) # rubocop:todo Performance/SelectMap
47
+ columns.select(&:virtual?).map(&:name)
48
48
  end
49
49
 
50
50
  def foreign_key_properties
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "js_regex"
4
-
5
3
  module Rhino
6
4
  module Resource
7
5
  module ActiveRecordExtension