Class: SweetyBacky::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/sweety_backy/utils.rb

Class Method Summary collapse

Class Method Details

.command(_command) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/sweety_backy/utils.rb', line 23

def self.command( _command )
  Utils.log "command: #{_command}"

  result = system(_command)

  raise "ERROR: on command: '#{_command}', result: '#{result}'" if !result
end

.is_last_day_of_month?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/sweety_backy/utils.rb', line 15

def self.is_last_day_of_month?
  return Date.new(Date.today.year, Date.today.month, -1) == Date.today
end

.is_last_day_of_week?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/sweety_backy/utils.rb', line 19

def self.is_last_day_of_week?
  return Date.today.cwday == 7
end

.is_last_day_of_year?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/sweety_backy/utils.rb', line 11

def self.is_last_day_of_year?
  return Date.new(Date.today.year, 12, -1) == Date.today
end

.log(msg) ⇒ Object



31
32
33
# File 'lib/sweety_backy/utils.rb', line 31

def self.log( msg )
  puts "#{Time.now.strftime("%Y-%m-%d %H:%M")}: #{msg}"
end

.namerize(path) ⇒ Object



35
36
37
# File 'lib/sweety_backy/utils.rb', line 35

def self.namerize( path )
  path.gsub('/', '.').gsub(/^\./, '')
end

.periodObject



4
5
6
7
8
9
# File 'lib/sweety_backy/utils.rb', line 4

def self.period
  return 'yearly'   if( is_last_day_of_year? )
  return 'monthly'  if( is_last_day_of_month? )
  return 'weekly'   if( is_last_day_of_week? )
  return 'daily'
end