Class: Easyhooks::Action
Constant Summary
Constants included from Validators
Validators::ALLOWED_METHODS, Validators::ALLOWED_ON_VALUES, Validators::ALLOWED_TYPES
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#event ⇒ Object
Returns the value of attribute event.
-
#event_callable ⇒ Object
Returns the value of attribute event_callable.
-
#on_fail_callable ⇒ Object
Returns the value of attribute on_fail_callable.
-
#trigger_name ⇒ Object
Returns the value of attribute trigger_name.
Attributes inherited from Base
#condition, #hook, #name, #on_fail, #payload, #type
Instance Method Summary collapse
-
#initialize(name, trigger_name, hook, args = {}, &event) ⇒ Action
constructor
A new instance of Action.
- #load!(klass_name = nil) ⇒ Object
Constructor Details
#initialize(name, trigger_name, hook, args = {}, &event) ⇒ Action
10 11 12 13 14 15 16 17 18 |
# File 'lib/easyhooks/action.rb', line 10 def initialize(name, trigger_name, hook, args = {}, &event) super(name, args[:type], hook, args[:if], args[:payload], args[:on_fail]) @args = args @trigger_name = trigger_name @event_callable = "#{name}_event".to_sym @on_fail_callable = "#{name}_on_fail".to_sym @event = event @hook = validate_hook(hook) end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
8 9 10 |
# File 'lib/easyhooks/action.rb', line 8 def args @args end |
#event ⇒ Object
Returns the value of attribute event.
8 9 10 |
# File 'lib/easyhooks/action.rb', line 8 def event @event end |
#event_callable ⇒ Object
Returns the value of attribute event_callable.
8 9 10 |
# File 'lib/easyhooks/action.rb', line 8 def event_callable @event_callable end |
#on_fail_callable ⇒ Object
Returns the value of attribute on_fail_callable.
8 9 10 |
# File 'lib/easyhooks/action.rb', line 8 def on_fail_callable @on_fail_callable end |
#trigger_name ⇒ Object
Returns the value of attribute trigger_name.
8 9 10 |
# File 'lib/easyhooks/action.rb', line 8 def trigger_name @trigger_name end |
Instance Method Details
#load!(klass_name = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/easyhooks/action.rb', line 20 def load!(klass_name = nil) return if self.type == :default stored_action = Store.find_by(name: self.name, context: 'actions') stored_action ||= Store.find_by(name: self.trigger_name, context: 'triggers') stored_action ||= Store.find_by(name: klass_name, context: 'classes') if klass_name.present? stored_action ||= Store.find_by(name: self.name, context: 'global') raise "Action '#{self.name}' not found in database" unless stored_action.present? # noinspection RubyArgCount self.hook.method = validate_method(stored_action.method) self.hook.endpoint = validate_endpoint(stored_action.endpoint) self.hook.auth = validate_auth(stored_action.auth) self.hook.headers = validate_headers(stored_action.headers) end |