Class: Ruboty::Routers::Base

Inherits:
Object
  • Object
show all
Extended by:
Mem
Includes:
Env::Validatable
Defined in:
lib/ruboty/routers/base.rb

Direct Known Subclasses

Root

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(robot) ⇒ Base

Returns a new instance of Base.



25
26
27
28
# File 'lib/ruboty/routers/base.rb', line 25

def initialize(robot)
  @robot = robot
  validate!
end

Instance Attribute Details

#robotObject (readonly)

Returns the value of attribute robot.



23
24
25
# File 'lib/ruboty/routers/base.rb', line 23

def robot
  @robot
end

Class Method Details

.actionsObject



15
16
17
# File 'lib/ruboty/routers/base.rb', line 15

def actions
  []
end

.inherited(child) ⇒ Object



7
8
9
# File 'lib/ruboty/routers/base.rb', line 7

def inherited(child)
  Ruboty::Router.routers << child
end

.route(path, options = {}) ⇒ Object



11
12
13
# File 'lib/ruboty/routers/base.rb', line 11

def route(path, options = {})
  actions << Router::Action.new(path, options)
end

Instance Method Details

#call(options = {}) ⇒ Object



30
31
32
33
34
# File 'lib/ruboty/routers/base.rb', line 30

def call(options = {})
  self.class.actions.inject({}) do |routes, action|
    routes.merge!(action.call(self, options))
  end
end