Module: LogStruct::Concerns::Configuration::ClassMethods
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
19 20 21 |
# File 'lib/log_struct/concerns/configuration.rb', line 19 def config LogStruct::Configuration.instance end |
#configuration ⇒ LogStruct::Configuration
(Can't use alias_method since this module is extended into LogStruct)
25 26 27 |
# File 'lib/log_struct/concerns/configuration.rb', line 25 def configuration config end |
#configuration=(config) ⇒ void
This method returns an undefined value.
Setter method to replace the configuration (for testing purposes)
31 32 33 |
# File 'lib/log_struct/concerns/configuration.rb', line 31 def configuration=(config) LogStruct::Configuration.set_instance(config) end |
#configure(&block) {|config| ... } ⇒ void
This method returns an undefined value.
14 15 16 |
# File 'lib/log_struct/concerns/configuration.rb', line 14 def configure(&block) yield(config) end |
#enabled? ⇒ Boolean
36 37 38 |
# File 'lib/log_struct/concerns/configuration.rb', line 36 def enabled? config.enabled end |
#is_local? ⇒ Boolean
60 61 62 |
# File 'lib/log_struct/concerns/configuration.rb', line 60 def is_local? config.local_environments.include?(::Rails.env.to_sym) end |
#is_production? ⇒ Boolean
65 66 67 |
# File 'lib/log_struct/concerns/configuration.rb', line 65 def is_production? !is_local? end |
#merge_rails_filter_parameters! ⇒ void
This method returns an undefined value.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/log_struct/concerns/configuration.rb', line 70 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) # Convert all Rails filter parameters to symbols and merge with our filter keys converted_params = rails_filter_params.map do |param| param.respond_to?(:to_sym) ? param.to_sym : param end # Add Rails filter parameters to our filter keys config.filters.filter_keys += converted_params # Ensure no duplicates config.filters.filter_keys.uniq! # Clear Rails filter parameters since we've incorporated them ::Rails.application.config.filter_parameters.clear end |
#set_enabled_from_rails_env! ⇒ void
This method returns an undefined value.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/log_struct/concerns/configuration.rb', line 41 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 # - Sets enabled=true only when value is "true" # - Sets enabled=false when value is "false" (or any non-"true") # 2. Otherwise, check if current Rails environment is in enabled_environments # 3. Otherwise, leave as config.enabled (defaults to true) # Then check if LOGSTRUCT_ENABLED env var is set config.enabled = if ENV["LOGSTRUCT_ENABLED"] # Override to true only if env var is "true" ENV["LOGSTRUCT_ENABLED"] == "true" else config.enabled_environments.include?(::Rails.env.to_sym) end end |