Class: Waylon::Sense

Inherits:
Object
  • Object
show all
Includes:
BaseComponent
Defined in:
lib/waylon/sense.rb

Overview

Base class for Senses (Usually messaging providers like Slack)

Direct Known Subclasses

RSpec::TestSense

Class Method Summary collapse

Methods included from BaseComponent

included

Class Method Details

.codify(text) ⇒ String

Almost always meant to be overridden, this is how the Sense wraps text in a code block

Parameters:

  • text (String)

    The string to codify

Returns:

  • (String)

    Properly wrapped content



11
12
13
# File 'lib/waylon/sense.rb', line 11

def self.codify(text)
  "```\n#{text}```"
end

.config_namespaceString

Config namespace for config keys

Returns:

  • (String)

    The namespace for config keys



17
18
19
# File 'lib/waylon/sense.rb', line 17

def self.config_namespace
  "senses.#{component_namespace}"
end

.enqueue(route, request) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The connection between Senses and Skills happens here, via a Route and a Hash of details

Parameters:

  • route (Route)

    route The matching Route from the SkillRegistry

  • request (String)

    The request message (or its ID) from the messaging platform



25
26
27
28
29
30
31
32
33
# File 'lib/waylon/sense.rb', line 25

def self.enqueue(route, request)
  details = {
    "sense" => self,
    "request" => request,
    "route" => route.name
  }

  Resque.enqueue route.destination, details
end

.group_classClass

Provides a simple mechanism for referencing the Group subclass provided by this Sense

Returns:

  • (Class)

    A Group subclass



37
38
39
# File 'lib/waylon/sense.rb', line 37

def self.group_class
  Group
end

.mention(user) ⇒ String

“At-mention” a User via the Sense. This is usually overridden on Sense subclasses.

Parameters:

Returns:

  • (String)


44
45
46
# File 'lib/waylon/sense.rb', line 44

def self.mention(user)
  "@#{user.handle}"
end

.message_classClass

Provides a simple mechanism for referencing the Message subclass provided by this Sense

Returns:

  • (Class)

    A Message subclass



50
51
52
# File 'lib/waylon/sense.rb', line 50

def self.message_class
  Message
end

.perform(content) ⇒ Object

Called by Resque to actually use this BaseComponent. Hands off to run() method

Parameters:

  • content (Hash)

    The payload hash for use in processing the message



56
57
58
# File 'lib/waylon/sense.rb', line 56

def self.perform(content)
  run(content)
end

.queueSymbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Redis/Resque queue name

Returns:

  • (Symbol)


63
64
65
# File 'lib/waylon/sense.rb', line 63

def self.queue
  :senses
end

.user_classClass

Provides a simple mechanism for referencing the User subclass provided by this Sense

Returns:

  • (Class)

    A User subclass



69
70
71
# File 'lib/waylon/sense.rb', line 69

def self.user_class
  User
end