Class: SlackBot::SlashCommandEndpointConfig

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

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.

Parameters:

  • url_token (Symbol)
  • config: (Config)
  • command_klass: (Class, nil) (defaults to: nil)
  • routes: (Hash[String, SlashCommandConfig]) (defaults to: {})
  • handler_name: (String, nil) (defaults to: nil)


145
146
147
148
149
150
151
152
153
154
155
# File 'lib/slack_bot/config.rb', line 145

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_klassClass? (readonly)

Returns the value of attribute command_klass.

Returns:

  • (Class, nil)


144
145
146
# File 'lib/slack_bot/config.rb', line 144

def command_klass
  @command_klass
end

#configConfig (readonly)

Returns the value of attribute config.

Returns:



144
145
146
# File 'lib/slack_bot/config.rb', line 144

def config
  @config
end

#routesHash[String, SlashCommandConfig] (readonly)

Returns the value of attribute routes.

Returns:



144
145
146
# File 'lib/slack_bot/config.rb', line 144

def routes
  @routes
end

#url_tokenSymbol (readonly)

Returns the value of attribute url_token.

Returns:

  • (Symbol)


144
145
146
# File 'lib/slack_bot/config.rb', line 144

def url_token
  @url_token
end

Instance Method Details

#command(command_token, command_klass, handler_name: nil) {|arg0| ... } ⇒ SlashCommandConfig

Parameters:

  • command_token (Symbol)
  • command_klass (Class)
  • handler_name: (String, nil) (defaults to: nil)

Yields:

Yield Parameters:

Yield Returns:

  • (void)

Returns:



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/slack_bot/config.rb', line 157

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_configsHash[Symbol, SlashCommandConfig]

Returns:



173
174
175
# File 'lib/slack_bot/config.rb', line 173

def command_configs
  @command_configs ||= {}
end

#find_command_config(text) ⇒ SlashCommandConfig?

Parameters:

  • text (String)

Returns:



177
178
179
180
181
182
183
184
185
# File 'lib/slack_bot/config.rb', line 177

def find_command_config(text)
  return if routes.blank?

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

  routes[route_key]
end

#full_tokenString

Returns:

  • (String)


187
188
189
# File 'lib/slack_bot/config.rb', line 187

def full_token
  ""
end