Class: Houston::Trigger

Inherits:
Struct
  • Object
show all
Defined in:
lib/houston/boot/triggers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(triggers, *args) ⇒ Trigger

Returns a new instance of Trigger.



42
43
44
45
# File 'lib/houston/boot/triggers.rb', line 42

def initialize(triggers, *args)
  @triggers = triggers
  super *args
end

Instance Attribute Details

#actionObject

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



40
41
42
# File 'lib/houston/boot/triggers.rb', line 40

def action
  @action
end

#method_nameObject

Returns the value of attribute method_name

Returns:

  • (Object)

    the current value of method_name



40
41
42
# File 'lib/houston/boot/triggers.rb', line 40

def method_name
  @method_name
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



40
41
42
# File 'lib/houston/boot/triggers.rb', line 40

def params
  @params
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



40
41
42
# File 'lib/houston/boot/triggers.rb', line 40

def value
  @value
end

Instance Method Details

#call(params = {}) ⇒ Object



55
56
57
58
# File 'lib/houston/boot/triggers.rb', line 55

def call(params={})
  options = { trigger: to_s, async: triggers.async }
  config.actions.run action, self.params.merge(params.to_h), options
end

#register!Object



47
48
49
50
51
52
53
# File 'lib/houston/boot/triggers.rb', line 47

def register!
  case method_name
  when :every then config.timer.every(value, &method(:call))
  when :on then config.observer.on(value, &method(:call))
  else raise NotImplementedError, "Unrecognized method name: #{method_name.inspect}"
  end
end

#to_sObject



60
61
62
# File 'lib/houston/boot/triggers.rb', line 60

def to_s
  "#{method_name}(#{value})"
end