Class: SlackBot::SlashCommandEndpointConfig
- Inherits:
-
Object
- Object
- SlackBot::SlashCommandEndpointConfig
- Defined in:
- lib/slack_bot/config.rb,
sig/slack_bot.rbs
Instance Attribute Summary collapse
-
#command_klass ⇒ Class?
readonly
Returns the value of attribute command_klass.
-
#config ⇒ Config
readonly
Returns the value of attribute config.
-
#routes ⇒ Hash[String, SlashCommandConfig]
readonly
Returns the value of attribute routes.
-
#url_token ⇒ Symbol
readonly
Returns the value of attribute url_token.
Instance Method Summary collapse
- #command(command_token, command_klass, handler_name: nil) {|arg0| ... } ⇒ SlashCommandConfig
- #command_configs ⇒ Hash[Symbol, SlashCommandConfig]
- #find_command_config(text) ⇒ SlashCommandConfig?
- #full_token ⇒ String
-
#initialize(url_token, config:, command_klass: nil, routes: {}, handler_name: nil) ⇒ SlashCommandEndpointConfig
constructor
A new instance of SlashCommandEndpointConfig.
Constructor Details
#initialize(url_token, config:, command_klass: nil, routes: {}, handler_name: nil) ⇒ SlashCommandEndpointConfig
Returns a new instance of SlashCommandEndpointConfig.
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_klass ⇒ Class? (readonly)
Returns the value of attribute command_klass.
144 145 146 |
# File 'lib/slack_bot/config.rb', line 144 def command_klass @command_klass end |
#config ⇒ Config (readonly)
Returns the value of attribute config.
144 145 146 |
# File 'lib/slack_bot/config.rb', line 144 def config @config end |
#routes ⇒ Hash[String, SlashCommandConfig] (readonly)
Returns the value of attribute routes.
144 145 146 |
# File 'lib/slack_bot/config.rb', line 144 def routes @routes end |
#url_token ⇒ Symbol (readonly)
Returns the value of attribute url_token.
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
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_configs ⇒ Hash[Symbol, SlashCommandConfig]
173 174 175 |
# File 'lib/slack_bot/config.rb', line 173 def command_configs @command_configs ||= {} end |
#find_command_config(text) ⇒ SlashCommandConfig?
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_token ⇒ String
187 188 189 |
# File 'lib/slack_bot/config.rb', line 187 def full_token "" end |