Class: Ruboty::Robot

Inherits:
Object
  • Object
show all
Includes:
Mem
Defined in:
lib/ruboty/robot.rb

Constant Summary collapse

DEFAULT_ENV =
"development"
DEFAULT_ROBOT_NAME =
"ruboty"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Robot

Returns a new instance of Robot.



12
13
14
# File 'lib/ruboty/robot.rb', line 12

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/ruboty/robot.rb', line 10

def options
  @options
end

Instance Method Details

#brainObject



48
49
50
# File 'lib/ruboty/robot.rb', line 48

def brain
  Brains::Base.find_class.new
end

#nameObject

ROBOT_NAME is deprecated.



44
45
46
# File 'lib/ruboty/robot.rb', line 44

def name
  ENV["RUBOTY_NAME"] || ENV["ROBOT_NAME"] || DEFAULT_ROBOT_NAME
end

#receive(attributes) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/ruboty/robot.rb', line 27

def receive(attributes)
  message = Message.new(attributes.merge(robot: self))
  unless handlers.inject(false) { |matched, handler| matched | handler.call(message) }
    handlers.each do |handler|
      handler.call(message, missing: true)
    end
  end
end

#runObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/ruboty/robot.rb', line 16

def run
  daemon
  dotenv
  bundle
  setup
  pid
  remember
  handle
  adapt
end

#say(*args) ⇒ Object



38
39
40
41
# File 'lib/ruboty/robot.rb', line 38

def say(*args)
  adapter.say(*args)
  true
end