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.



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

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.



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

def command_klass
  @command_klass
end

#endpointObject

Returns the value of attribute endpoint.



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

def endpoint
  @endpoint
end

#parent_configsObject

Returns the value of attribute parent_configs.



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

def parent_configs
  @parent_configs
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

Class Method Details

.delimiterObject



141
142
143
# File 'lib/slack_bot/config.rb', line 141

def self.delimiter
  " "
end

Instance Method Details

#argument_command(argument_token, klass = nil) ⇒ Object



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

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



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

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

#full_tokenObject



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

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

#url_tokenObject



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

def url_token
  endpoint.url_token
end