Module: Robut::Plugin::ClassMethods
- Defined in:
- lib/robut/plugin.rb
Overview
Contains methods that will be added directly to a class including Robut::Plugin.
Instance Method Summary collapse
-
#desc(string) ⇒ Object
Provides a description for the next matcher.
-
#http(&block) ⇒ Object
Allows you to define http methods that this plugin should respond to.
-
#match(regexp, options = {}, &action) ⇒ Object
Sets up a ‘matcher’ that will try to match input being sent to this plugin with a regular expression.
-
#matchers ⇒ Object
A list of regular expressions to apply to input being sent to the plugin, along with blocks of actions to perform.
Instance Method Details
#desc(string) ⇒ Object
Provides a description for the next matcher
33 34 35 |
# File 'lib/robut/plugin.rb', line 33 def desc(string) @last_description = string end |
#http(&block) ⇒ Object
Allows you to define http methods that this plugin should respond to. This is useful if you’re want to accept generic post data for Robut to display in all rooms (e.g. Heroku deploy hooks, GitHub post receive hooks, etc).
http do
post '/heroku' do
payload = Hashie::Mash.new(params)
say "#{payload.user} deployed #{payload.head} to #{payload.app}", nil
halt 200
end
end
The action is run in the context of a Sinatra app (Robut::Web). So anything that Sinatra provides is available within the block.
59 60 61 |
# File 'lib/robut/plugin.rb', line 59 def http(&block) Robut::Web.class_eval &block end |
#match(regexp, options = {}, &action) ⇒ Object
Sets up a ‘matcher’ that will try to match input being sent to this plugin with a regular expression. If the expression matches, action will be performed. action will be passed any captured groups in the regular expression as parameters. For example:
match /^say hello to (\w+)/ do |name| ...
The action is run in the context of an instance of a class that includes Robut::Plugin. Like handle, an action explicitly returning true will stop the plugin chain from matching any further.
Supported options:
:sent_to_me - only try to match this regexp if it contains an @reply to robut.
This will also strip the @reply from the message we're trying
to match on, so ^ and $ will still do the right thing.
27 28 29 30 |
# File 'lib/robut/plugin.rb', line 27 def match(regexp, = {}, &action) matchers << [regexp, , action, @last_description] @last_description = nil end |
#matchers ⇒ Object
A list of regular expressions to apply to input being sent to the plugin, along with blocks of actions to perform. Each element is a [regexp, options, action, description] array.
40 41 42 |
# File 'lib/robut/plugin.rb', line 40 def matchers @matchers ||= [] end |