Module: BundlerSkills::Disabling
- Defined in:
- lib/bundler_skills/disabling.rb
Overview
Decides whether the plugin should run in the current environment.
Skills are a development-time concern, so the hook is silently disabled in production / CI. All inputs are injected (env hash + config) so the logic is a pure function and easy to test. The manual ‘bundle skills` command does NOT consult this — an explicit user action always runs.
Constant Summary collapse
- TRUTHY =
%w[1 true yes on].freeze
Class Method Summary collapse
- .ci?(env) ⇒ Boolean
-
.current_environment(env) ⇒ Object
Best-effort current environment name for ‘enabled:` list matching.
-
.disabled?(env: ENV, config: nil) ⇒ Boolean
True when the plugin must not run.
- .production?(env) ⇒ Boolean
- .truthy?(value) ⇒ Boolean
Class Method Details
.ci?(env) ⇒ Boolean
46 47 48 |
# File 'lib/bundler_skills/disabling.rb', line 46 def ci?(env) truthy?(env["CI"]) end |
.current_environment(env) ⇒ Object
Best-effort current environment name for ‘enabled:` list matching.
51 52 53 54 |
# File 'lib/bundler_skills/disabling.rb', line 51 def current_environment(env) value = env["RAILS_ENV"] || env["RACK_ENV"] value.to_s.strip.empty? ? "development" : value.strip.downcase end |
.disabled?(env: ENV, config: nil) ⇒ Boolean
Returns true when the plugin must not run.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bundler_skills/disabling.rb', line 18 def disabled?(env: ENV, config: nil) # Explicit overrides win over everything else. return true if truthy?(env["BUNDLER_SKILLS_DISABLED"]) return false if truthy?(env["BUNDLER_SKILLS_ENABLED"]) enabled = config&.enabled case enabled when false return true when Array return true unless enabled.map(&:to_s).include?(current_environment(env)) when true return false end production?(env) || ci?(env) end |
.production?(env) ⇒ Boolean
42 43 44 |
# File 'lib/bundler_skills/disabling.rb', line 42 def production?(env) %w[RAILS_ENV RACK_ENV].any? { |key| env[key].to_s.strip.downcase == "production" } end |
.truthy?(value) ⇒ Boolean
36 37 38 39 40 |
# File 'lib/bundler_skills/disabling.rb', line 36 def truthy?(value) return false if value.nil? TRUTHY.include?(value.to_s.strip.downcase) end |