Module: LogStruct::Concerns::Configuration::ClassMethods
Constant Summary collapse
- SERVER_COMMAND_ARGS =
T.let(["server", "s"].freeze, T::Array[String])
- CONSOLE_COMMAND_ARGS =
T.let(["console", "c"].freeze, T::Array[String])
- EMPTY_ARGV =
T.let([].freeze, T::Array[String])
- CI_FALSE_VALUES =
T.let(["false", "0", "no"].freeze, T::Array[String])
Instance Method Summary collapse
- #config ⇒ LogStruct::Configuration
-
#configuration ⇒ LogStruct::Configuration
(Can't use alias_method since this module is extended into LogStruct).
-
#configuration=(config) ⇒ void
Setter method to replace the configuration (for testing purposes).
- #configure(&block) {|config| ... } ⇒ void
- #enabled? ⇒ Boolean
- #is_local? ⇒ Boolean
- #is_production? ⇒ Boolean
- #merge_rails_filter_parameters! ⇒ void
- #set_enabled_from_rails_env! ⇒ void
Instance Method Details
#config ⇒ LogStruct::Configuration
24 25 26 |
# File 'lib/log_struct/concerns/configuration.rb', line 24 def config LogStruct::Configuration.instance end |
#configuration ⇒ LogStruct::Configuration
(Can't use alias_method since this module is extended into LogStruct)
30 31 32 |
# File 'lib/log_struct/concerns/configuration.rb', line 30 def configuration config end |
#configuration=(config) ⇒ void
This method returns an undefined value.
Setter method to replace the configuration (for testing purposes)
36 37 38 |
# File 'lib/log_struct/concerns/configuration.rb', line 36 def configuration=(config) LogStruct::Configuration.set_instance(config) end |
#configure(&block) {|config| ... } ⇒ void
This method returns an undefined value.
19 20 21 |
# File 'lib/log_struct/concerns/configuration.rb', line 19 def configure(&block) yield(config) end |
#enabled? ⇒ Boolean
41 42 43 |
# File 'lib/log_struct/concerns/configuration.rb', line 41 def enabled? config.enabled end |
#is_local? ⇒ Boolean
71 72 73 |
# File 'lib/log_struct/concerns/configuration.rb', line 71 def is_local? config.local_environments.include?(::Rails.env.to_sym) end |
#is_production? ⇒ Boolean
76 77 78 |
# File 'lib/log_struct/concerns/configuration.rb', line 76 def is_production? !is_local? end |
#merge_rails_filter_parameters! ⇒ void
This method returns an undefined value.
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 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/log_struct/concerns/configuration.rb', line 81 def merge_rails_filter_parameters! return unless ::Rails.application.config.respond_to?(:filter_parameters) rails_filter_params = ::Rails.application.config.filter_parameters return unless rails_filter_params.is_a?(Array) return if rails_filter_params.empty? symbol_filters = T.let([], T::Array[Symbol]) matchers = T.let([], T::Array[ConfigStruct::FilterMatcher]) leftovers = T.let([], T::Array[T.untyped]) rails_filter_params.each do |entry| matcher = build_filter_matcher(entry) if matcher matchers << matcher next end normalized_symbol = normalize_filter_symbol(entry) if normalized_symbol symbol_filters << normalized_symbol else leftovers << entry end end if symbol_filters.any? config.filters.filter_keys |= symbol_filters end if matchers.any? matchers.each do |matcher| existing = config.filters.filter_matchers.any? do |registered| registered.label == matcher.label end config.filters.filter_matchers << matcher unless existing end end replace_filter_parameters(rails_filter_params, leftovers) end |
#set_enabled_from_rails_env! ⇒ void
This method returns an undefined value.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/log_struct/concerns/configuration.rb', line 46 def set_enabled_from_rails_env! # Set enabled based on current Rails environment and the LOGSTRUCT_ENABLED env var. # Precedence: # 1. Check if LOGSTRUCT_ENABLED env var is defined (not an empty string) # - Sets enabled=true only when value is "true", "yes", "1", etc. # - Sets enabled=false when value is any other value # 2. Otherwise, check if current Rails environment is in enabled_environments # AND one of: Rails::Server is defined, OR test environment with CI=true # BUT NOT Rails::Console (to exclude interactive console) # 3. Otherwise, leave as config.enabled (defaults to true) # Then check if LOGSTRUCT_ENABLED env var is set config.enabled = if ENV["LOGSTRUCT_ENABLED"] %w[true t yes y 1].include?(ENV["LOGSTRUCT_ENABLED"]&.strip&.downcase) else is_console = console_process? is_server = server_process? ci_build? in_enabled_env = config.enabled_environments.include?(::Rails.env.to_sym) in_enabled_env && !is_console && (is_server || ::Rails.env.test?) end end |