Class: SlackBot::SlashCommandConfig

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_klass:, token:, endpoint:, parent_configs: [], handler_name: nil) ⇒ SlashCommandConfig

Returns a new instance of SlashCommandConfig.



150
151
152
153
154
155
156
157
158
159
160
# File 'lib/slack_bot/config.rb', line 150

def initialize(command_klass:, token:, endpoint:, parent_configs: [], handler_name: nil)
  @command_klass = command_klass
  @token = token
  @parent_configs = parent_configs || []
  @endpoint = endpoint

  endpoint.routes[full_token] = self

  handler_name ||= command_klass.name
  endpoint.config.handler_class(handler_name, command_klass)
end

Instance Attribute Details

#command_klassObject

Returns the value of attribute command_klass.



149
150
151
# File 'lib/slack_bot/config.rb', line 149

def command_klass
  @command_klass
end

#endpointObject

Returns the value of attribute endpoint.



149
150
151
# File 'lib/slack_bot/config.rb', line 149

def endpoint
  @endpoint
end

#parent_configsObject

Returns the value of attribute parent_configs.



149
150
151
# File 'lib/slack_bot/config.rb', line 149

def parent_configs
  @parent_configs
end

#tokenObject

Returns the value of attribute token.



149
150
151
# File 'lib/slack_bot/config.rb', line 149

def token
  @token
end

Class Method Details

.delimiterObject



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

def self.delimiter
  " "
end

Instance Method Details

#argument_command(argument_token, klass = nil) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/slack_bot/config.rb', line 162

def argument_command(argument_token, klass = nil, &)
  @argument_command_configs ||= {}
  @argument_command_configs[argument_token.to_sym] ||=
    SlashCommandConfig.new(
      command_klass: command_klass,
      token: argument_token,
      parent_configs: [self] + (parent_configs || []),
      endpoint: endpoint
    )

  command_config = @argument_command_configs[argument_token.to_sym]
  command_config.instance_eval(&) if block_given?

  command_config
end

#find_argument_command_config(argument_token) ⇒ Object



178
179
180
181
# File 'lib/slack_bot/config.rb', line 178

def find_argument_command_config(argument_token)
  @argument_command_configs ||= {}
  @argument_command_configs[argument_token.to_sym]
end

#full_tokenObject



183
184
185
186
187
# File 'lib/slack_bot/config.rb', line 183

def full_token
  [parent_configs.map(&:token), token].flatten.compact.join(
    self.class.delimiter
  )
end

#url_tokenObject



189
190
191
# File 'lib/slack_bot/config.rb', line 189

def url_token
  endpoint.url_token
end