Module: Stackify::Utils
- Defined in:
- lib/stackify/utils/methods.rb
Class Method Summary collapse
- .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
- .rounded_current_time ⇒ Object
Class Method Details
.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 |
.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 |