Method: Parse::Webhooks.route

Defined in:
lib/parse/webhooks.rb

.route(type, className, block = nil) { ... } ⇒ OpenStruct

Internally registers a route for a specific webhook trigger or function. ‘:before_delete`, `:after_delete` or `:function`.

Parameters:

  • type (Symbol)

    The type of cloud code webhook to register. This can be any of the supported routes. These are ‘:before_save`, `:after_save`,

  • className (String)

    if ‘type` is not `:function`, then this registers a trigger for the given className. Otherwise, className is treated to be the function name to register with Parse server.

Yields:

  • the block that will handle of the webhook trigger or function.

Returns:

  • (OpenStruct)


128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/parse/webhooks.rb', line 128

def route(type, className, block = nil)
  type = type.to_s.underscore.to_sym #support camelcase
  if type != :function && className.respond_to?(:parse_class)
    className = className.parse_class
  end
  className = className.to_s
  block = Proc.new if block_given?
  if routes[type].nil? || block.respond_to?(:call) == false
    raise ArgumentError, "Invalid Webhook registration trigger #{type} #{className}"
  end

  # AfterSave/AfterDelete hooks support more than one
  if type == :after_save || type == :after_delete
    routes[type][className] ||= []
    routes[type][className].push block
  else
    routes[type][className] = block
  end
  @routes
end