Class: SensuGenerator::Trigger

Inherits:
Object
  • Object
show all
Defined in:
lib/sensu_generator/trigger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTrigger

Returns a new instance of Trigger.



5
6
7
8
9
# File 'lib/sensu_generator/trigger.rb', line 5

def initialize
  init_value = Time.now.to_f
  @previous = init_value
  @last     = init_value
end

Instance Attribute Details

#lastObject (readonly)

Returns the value of attribute last.



3
4
5
# File 'lib/sensu_generator/trigger.rb', line 3

def last
  @last
end

#previousObject (readonly)

Returns the value of attribute previous.



3
4
5
# File 'lib/sensu_generator/trigger.rb', line 3

def previous
  @previous
end

Instance Method Details

#clearObject



25
26
27
28
29
30
# File 'lib/sensu_generator/trigger.rb', line 25

def clear
  logger.info "Clear trigger!"
  time      = Time.now.to_f
  @previous = time
  @last     = time
end

#difference_between_touchesObject



17
18
19
# File 'lib/sensu_generator/trigger.rb', line 17

def difference_between_touches
  @last - @previous
end

#last_touch_ageObject



21
22
23
# File 'lib/sensu_generator/trigger.rb', line 21

def last_touch_age
  Time.now.to_f - @last
end

#loggerObject



36
37
38
# File 'lib/sensu_generator/trigger.rb', line 36

def logger
  @logger ||= Application.logger
end

#modified_since_last_update?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/sensu_generator/trigger.rb', line 32

def modified_since_last_update?
  @previous != @last
end

#touchObject



11
12
13
14
15
# File 'lib/sensu_generator/trigger.rb', line 11

def touch
  logger.info "Touch trigger!"
  @previous = @last
  @last = Time.now.to_f
end