Class: SlackBot::SlashCommandEndpointConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/slack_bot/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url_token, config:, command_klass: nil, routes: {}, handler_name: nil) ⇒ SlashCommandEndpointConfig

Returns a new instance of SlashCommandEndpointConfig.



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/slack_bot/config.rb', line 96

def initialize(url_token, config:, command_klass: nil, routes: {}, handler_name: nil)
  @url_token = url_token
  @command_klass = command_klass
  @routes = routes
  @config = config

  if command_klass.present?
    handler_name ||= command_klass.name
    config.handler_class(handler_name, command_klass)
  end
end

Instance Attribute Details

#command_klassObject (readonly)

Returns the value of attribute command_klass.



95
96
97
# File 'lib/slack_bot/config.rb', line 95

def command_klass
  @command_klass
end

#configObject (readonly)

Returns the value of attribute config.



95
96
97
# File 'lib/slack_bot/config.rb', line 95

def config
  @config
end

#routesObject (readonly)

Returns the value of attribute routes.



95
96
97
# File 'lib/slack_bot/config.rb', line 95

def routes
  @routes
end

#url_tokenObject (readonly)

Returns the value of attribute url_token.



95
96
97
# File 'lib/slack_bot/config.rb', line 95

def url_token
  @url_token
end

Instance Method Details

#command(command_token, command_klass, handler_name: nil) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/slack_bot/config.rb', line 108

def command(command_token, command_klass, handler_name: nil, &)
  @command_configs ||= {}
  @command_configs[command_token.to_sym] ||=
    begin
      command =
        SlashCommandConfig.new(
          command_klass: command_klass,
          token: command_token,
          endpoint: self,
          handler_name: handler_name
        )
      command.instance_eval(&) if block_given?
      command
    end
end

#command_configsObject



124
125
126
# File 'lib/slack_bot/config.rb', line 124

def command_configs
  @command_configs ||= {}
end

#find_command_config(text) ⇒ Object



128
129
130
131
132
133
# File 'lib/slack_bot/config.rb', line 128

def find_command_config(text)
  route_key = text.scan(/^(#{routes.keys.join("|")})(?:\s|$)/).flatten.first
  return if route_key.blank?

  routes[route_key]
end

#full_tokenObject



135
136
137
# File 'lib/slack_bot/config.rb', line 135

def full_token
  ""
end