Module: Modulorails
- Defined in:
- lib/modulorails.rb,
lib/modulorails/data.rb,
lib/modulorails/railtie.rb,
lib/modulorails/version.rb,
lib/modulorails/configuration.rb,
lib/modulorails/generators/base.rb,
lib/modulorails/generators/docker_base.rb,
lib/generators/modulorails/docker/docker_generator.rb,
lib/generators/modulorails/githooks/githooks_generator.rb,
lib/generators/modulorails/docker/config/config_generator.rb,
lib/generators/modulorails/docker/compose/compose_generator.rb,
lib/generators/modulorails/docker/dockerfile/dockerfile_generator.rb,
lib/generators/modulorails/docker/entrypoint/entrypoint_generator.rb,
lib/generators/modulorails/docker/devcontainer/devcontainer_generator.rb
Overview
Author: Matthieu ‘ciappa_m’ Ciappara The entry point of the gem. It exposes the configurator, the gathered data and the method to send those data to the intranet.
Defined Under Namespace
Modules: ApplicationHelper, Docker, Generators Classes: BaseError, BaseService, BundlerauditGenerator, ClaudeCodeGenerator, Configuration, Data, DockerGenerator, Error, ErrorData, GithooksGenerator, GitlabciGenerator, HealthCheckGenerator, InvalidFormatError, InvalidValueError, LogsForMethodService, ModuloprojectGenerator, Railtie, RubocopGenerator, SelfUpdateGenerator, ServiceGenerator, SidekiqGenerator, SuccessData
Constant Summary collapse
- VERSION =
'1.7.0'.freeze
- COMPARABLE_RUBY_VERSION =
Useful to compare the current Ruby version
Gem::Version.new(RUBY_VERSION)
Class Attribute Summary collapse
-
.configuration ⇒ Modulorails::Configuration
A configuration getter.
Class Method Summary collapse
-
.configure {|configuration| ... } ⇒ Modulorails::Configuration
When a block is given, it allows to define or update the current configuration.
-
.configure_claude_code ⇒ Object
Configure devcontainer for Claude code unless it was already done.
-
.data ⇒ Modulorails::Data
A data getter.
- .deprecator ⇒ Object
-
.generate_bundleraudit_template ⇒ Object
Generate a bundler-audit configuration.
-
.generate_ci_template ⇒ Object
Generate a CI/CD template unless it was already done.
-
.generate_docker_template ⇒ Object
Generate a Docker config template unless it was already done.
-
.generate_git_hooks_template ⇒ Object
Generate git hooks.
-
.generate_healthcheck_template ⇒ Object
Generate a health_check configuration unless it was already done.
-
.generate_rubocop_template ⇒ Object
Generate a rubocop configuration unless it was already done.
-
.self_update ⇒ Object
Check the last version of Modulorails available on rubygems and update if there was a publication.
-
.send_data ⇒ HTTParty::Response
Send the ‘#data` to the Intranet as JSON.
Class Attribute Details
.configuration ⇒ Modulorails::Configuration
A configuration getter.
58 59 60 |
# File 'lib/modulorails.rb', line 58 def configuration @configuration ||= Modulorails::Configuration.new end |
Class Method Details
.configure {|configuration| ... } ⇒ Modulorails::Configuration
When a block is given, it allows to define or update the current configuration. Without a block, this methods is just a configuration getter.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/modulorails.rb', line 41 def configure # Get the current configuration if no block is given return configuration unless block_given? # Pass the configuration to the block and let the block do what it wants (probably update the # configuration) yield configuration # Return the (probably updated) current configuration configuration end |
.configure_claude_code ⇒ Object
Configure devcontainer for Claude code unless it was already done. The check is done using a ‘keepfile’.
175 176 177 |
# File 'lib/modulorails.rb', line 175 def configure_claude_code Modulorails::ClaudeCodeGenerator.new([], {}, {}).invoke_all end |
.data ⇒ Modulorails::Data
A data getter.
67 68 69 |
# File 'lib/modulorails.rb', line 67 def data @data ||= Modulorails::Data.new end |
.deprecator ⇒ Object
179 180 181 |
# File 'lib/modulorails.rb', line 179 def deprecator @deprecator ||= ActiveSupport::Deprecation.new('2.0', 'Modulorails') end |
.generate_bundleraudit_template ⇒ Object
Generate a bundler-audit configuration.
160 161 162 |
# File 'lib/modulorails.rb', line 160 def generate_bundleraudit_template Modulorails::BundlerauditGenerator.new([], {}, {}).invoke_all end |
.generate_ci_template ⇒ Object
Generate a CI/CD template unless it was already done. The check is done using a ‘keepfile’.
125 126 127 |
# File 'lib/modulorails.rb', line 125 def generate_ci_template Modulorails::GitlabciGenerator.new([], {}, {}).invoke_all end |
.generate_docker_template ⇒ Object
Generate a Docker config template unless it was already done. The check is done using a ‘keepfile’.
117 118 119 |
# File 'lib/modulorails.rb', line 117 def generate_docker_template Modulorails::DockerGenerator.new([], {}, {}).invoke_all end |
.generate_git_hooks_template ⇒ Object
Generate git hooks.
167 168 169 |
# File 'lib/modulorails.rb', line 167 def generate_git_hooks_template Modulorails::GithooksGenerator.new([], {}, {}).invoke_all end |
.generate_healthcheck_template ⇒ Object
Generate a health_check configuration unless it was already done. The check is done using a ‘keepfile’.
145 146 147 |
# File 'lib/modulorails.rb', line 145 def generate_healthcheck_template Modulorails::HealthCheckGenerator.new([], {}, {}).invoke_all end |
.generate_rubocop_template ⇒ Object
Generate a rubocop configuration unless it was already done. The check is done using a ‘keepfile’.
153 154 155 |
# File 'lib/modulorails.rb', line 153 def generate_rubocop_template Modulorails::RubocopGenerator.new([], {}, {}).invoke_all end |
.self_update ⇒ Object
Check the last version of Modulorails available on rubygems and update if there was a publication
133 134 135 136 137 138 139 |
# File 'lib/modulorails.rb', line 133 def self_update return if configuration.no_auto_update Modulorails::SelfUpdateGenerator.new([], {}, {}).invoke_all rescue StandardError => e Rails.logger&.debug { "[Modulorails] An error occured: #{e.class} - #{e.}" } end |
.send_data ⇒ HTTParty::Response
Send the ‘#data` to the Intranet as JSON. HTTParty is used to send the POST request.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/modulorails.rb', line 77 def send_data # If no endpoint and/or no API key is configured, it is impossible to send the data to the # intranet and thus we raise an error: it is the only error we want to raise since it goes # against one of the main goals of the gem and the gem's user is responsible. raise Error.new('No endpoint or api key') unless configuration.endpoint && configuration.api_key # Define the headers of the request ; sending JSON and API key to authenticate the gem on # the intranet headers = { 'Content-Type' => 'application/json', 'X-MODULORAILS-TOKEN' => configuration.api_key } # Define the JSON body of the request body = data.to_params.to_json # Prevent HTTParty to raise error and crash the server in dev begin # Post to the configured endpoint on the Intranet response = HTTParty.post(configuration.endpoint, headers: headers, body: body) # According to the API specification, on a "Bad request" response, the server explicits what # went wrong with an `errors` field. We do not want to raise since the gem's user is not # (necessarily) responsible for the error but we still need to display it somewhere to warn # the user something went wrong. Rails.logger&.debug { "[Modulorails] Error: #{response['errors'].join(', ')}" } if response.code == 400 # Return the response to allow users to do some more response rescue StandardError => e # Still need to notify the user Rails.logger&.debug { "[Modulorails] Error: Could not post to #{configuration.endpoint}" } Rails.logger&.debug e. nil end end |