Module: Lita::Handler::Common

Defined in:
lib/lita/handler/common.rb

Overview

Methods included in any class that includes at least one type of router.

Since:

  • 4.0.0

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#redisRedis::Namespace (readonly)

A Redis::Namespace scoped to the handler.

Since:

  • 4.0.0


30
31
32
# File 'lib/lita/handler/common.rb', line 30

def redis
  @redis
end

#robotLita::Robot (readonly)

The running Robot instance.

Since:

  • 4.0.0


34
35
36
# File 'lib/lita/handler/common.rb', line 34

def robot
  @robot
end

Class Method Details

.included(klass) ⇒ Object

Adds common functionality to the class and initializes the handler's configuration builder.

Since:

  • 4.0.0


7
8
9
10
11
12
# File 'lib/lita/handler/common.rb', line 7

def self.included(klass)
  klass.extend(ClassMethods)
  klass.extend(Namespace)
  klass.extend(Configurable)
  klass.configuration_builder = ConfigurationBuilder.new
end

Instance Method Details

#after(interval) {|timer| ... } ⇒ void

This method returns an undefined value.

Invokes the given block after the given number of seconds.

Yield Parameters:

Since:

  • 3.0.0


47
48
49
# File 'lib/lita/handler/common.rb', line 47

def after(interval, &block)
  Thread.new { Timer.new(interval: interval, &block).start }
end

#configLita::Configuration, Lita::Config

The handler's configuration object.

Since:

  • 3.2.0


54
55
56
57
58
# File 'lib/lita/handler/common.rb', line 54

def config
  if robot.config.handlers.respond_to?(self.class.namespace)
    robot.config.handlers.public_send(self.class.namespace)
  end
end

#every(interval) {|timer| ... } ⇒ void

Note:

The block should call Timer#stop at a terminating condition to avoid infinite recursion.

This method returns an undefined value.

Invokes the given block repeatedly, waiting the given number of seconds between each invocation.

Yield Parameters:

Since:

  • 3.0.0


68
69
70
# File 'lib/lita/handler/common.rb', line 68

def every(interval, &block)
  Thread.new { Timer.new(interval: interval, recurring: true, &block).start }
end

#http(options = {}) {|builder| ... } ⇒ Faraday::Connection

Creates a new Faraday::Connection for making HTTP requests.

Yields:

  • (builder)

    A Faraday builder object for adding middleware.

Since:

  • 4.0.0


76
77
78
79
80
81
82
83
84
# File 'lib/lita/handler/common.rb', line 76

def http(options = {}, &block)
  options = default_faraday_options.merge(options)

  if block
    Faraday::Connection.new(nil, options, &block)
  else
    Faraday::Connection.new(nil, options)
  end
end

#initialize(robot) ⇒ Object

Since:

  • 4.0.0


37
38
39
40
# File 'lib/lita/handler/common.rb', line 37

def initialize(robot)
  @robot = robot
  @redis = Redis::Namespace.new(redis_namespace, redis: Lita.redis)
end

#logLita::Logger

The Lita logger.

Since:

  • 3.2.0


89
90
91
# File 'lib/lita/handler/common.rb', line 89

def log
  Lita.logger
end

#translate(*args) ⇒ Object Also known as: t

See Also:

Since:

  • 4.0.0


94
95
96
# File 'lib/lita/handler/common.rb', line 94

def translate(*args)
  self.class.translate(*args)
end