Module: Stackify::Utils

Defined in:
lib/stackify/utils/methods.rb

Class Method Summary collapse

Class Method Details

.current_minuteObject



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
# File 'lib/stackify/utils/methods.rb', line 16

def self.do_only_if_authorized_and_mode_is_on mode, &block
  if Stackify.configuration.api_enabled
    if Stackify.authorized?
      if is_mode_on? mode
        yield
      else
        Stackify.internal_log :warn, "#{caller[0]}: Skipped because mode - #{mode.to_s} is disabled at configuration"
      end
    else
      Stackify.internal_log :warn, "#{caller[0]}: Skipped due to authorization failure"
    end
  end
end

.is_api_enabledObject



30
31
32
33
34
35
# File 'lib/stackify/utils/methods.rb', line 30

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

Returns:

  • (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_timeObject



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