Module: Stackify::Utils
- Defined in:
- lib/stackify/utils/methods.rb
Class Method Summary collapse
-
.check_buffered_logger ⇒ Object
Check if the rails version 3 and it’s using the buffered logger.
-
.check_log_output ⇒ Object
Check if the app is running on rails and the logger output is using STDOUT.
- .current_minute ⇒ Object
- .do_only_if_authorized_and_mode_is_on(mode, &block) ⇒ Object
- .get_app_settings ⇒ Object
- .is_api_enabled ⇒ Object
- .is_mode_on?(mode) ⇒ Boolean
- .logger_stdout ⇒ Object
- .rounded_current_time ⇒ Object
Class Method Details
.check_buffered_logger ⇒ Object
Check if the rails version 3 and it’s using the buffered logger
69 70 71 72 73 |
# File 'lib/stackify/utils/methods.rb', line 69 def self.check_buffered_logger is_buffered_logger = false is_buffered_logger = true if ::Rails.logger.is_a?(ActiveSupport::BufferedLogger) Stackify.configuration.buffered_logger = is_buffered_logger end |
.check_log_output ⇒ Object
Check if the app is running on rails and the logger output is using STDOUT
51 52 53 54 55 56 57 58 59 |
# File 'lib/stackify/utils/methods.rb', line 51 def self.check_log_output if defined? Rails if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('5.0') Stackify.configuration.stdout_output = ActiveSupport::Logger.logger_outputs_to?(Rails.logger, STDOUT) else Stackify.configuration.stdout_output = self.logger_stdout end end end |
.current_minute ⇒ Object
3 4 5 |
# File 'lib/stackify/utils/methods.rb', line 3 def self.current_minute Time.now.utc.to_i/60 end |
.do_only_if_authorized_and_mode_is_on(mode, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stackify/utils/methods.rb', line 16 def self. mode, &block begin if Stackify.configuration.api_enabled if Stackify. if is_mode_on? mode yield else Stackify.internal_log :warn, "[Stackify::Utils] - #{caller[0]}: Skipped because mode - #{mode.to_s} is disabled at configuration" end else Stackify.internal_log :warn, "[Stackify::Utils] - #{caller[0]}: Skipped due to authorization failure" end end rescue => ex Stackify.internal_log :warn, "[Stackify::Utils] do_only_if_authorized_and_mode_is_on ex: #{ex.inspect}" end end |
.get_app_settings ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/stackify/utils/methods.rb', line 41 def self.get_app_settings @env = { 'env' => Stackify.configuration.env, 'app_name' => Stackify.configuration.app_name, 'server_name' => Socket.gethostname, 'app_location' => Stackify.configuration.app_location || Dir.pwd } end |
.is_api_enabled ⇒ Object
34 35 36 37 38 39 |
# File 'lib/stackify/utils/methods.rb', line 34 def self.is_api_enabled exclude = %w/rake rspec irb/ cmd = $PROGRAM_NAME.to_s.split('/').pop found = exclude.select{|e| e =~ /#{cmd}/i} Stackify.configuration.api_enabled = false if found.count > 0 end |
.is_mode_on?(mode) ⇒ Boolean
12 13 14 |
# File 'lib/stackify/utils/methods.rb', line 12 def self.is_mode_on? mode Stackify.configuration.mode = mode || Stackify::MODES[:both] end |
.logger_stdout ⇒ Object
61 62 63 64 65 66 |
# File 'lib/stackify/utils/methods.rb', line 61 def self.logger_stdout logdev = ::Rails.logger.instance_variable_get(:@logdev) logger_source = logdev.dev if logdev.respond_to?(:dev) sources = [$stdout] found = sources.any? { |source| source == logger_source } end |
.rounded_current_time ⇒ Object
7 8 9 10 |
# File 'lib/stackify/utils/methods.rb', line 7 def self.rounded_current_time t = Time.now.utc t - t.sec end |