Class: SlackBot::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#callback_storage_instanceObject (readonly)

Returns the value of attribute callback_storage_instance.

Returns:

  • (Object)


15
16
17
# File 'lib/slack_bot/config.rb', line 15

def callback_storage_instance
  @callback_storage_instance
end

#callback_user_finder_methodProc (readonly)

Returns the value of attribute callback_user_finder_method.

Returns:

  • (Proc)


28
29
30
# File 'lib/slack_bot/config.rb', line 28

def callback_user_finder_method
  @callback_user_finder_method
end

#event_dispatcher_methodProc (readonly)

Returns the value of attribute event_dispatcher_method.

Returns:

  • (Proc)


54
55
56
# File 'lib/slack_bot/config.rb', line 54

def event_dispatcher_method
  @event_dispatcher_method
end

#user_session_resolver_methodProc (readonly)

Returns the value of attribute user_session_resolver_method.

Returns:

  • (Proc)


41
42
43
# File 'lib/slack_bot/config.rb', line 41

def user_session_resolver_method
  @user_session_resolver_method
end

Class Method Details

.configure {|arg0| ... } ⇒ void

This method returns an undefined value.

Yields:

Yield Parameters:

Yield Returns:

  • (void)


11
12
13
# File 'lib/slack_bot/config.rb', line 11

def self.configure(&)
  current_instance.instance_eval(&)
end

.current_instanceConfig

Returns:



6
7
8
9
# File 'lib/slack_bot/config.rb', line 6

def self.current_instance
  @@current_instances ||= {}
  @@current_instances[name] ||= new
end

Instance Method Details

#block_action(action_id, interaction_klass, handler_name: nil) ⇒ void

This method returns an undefined value.

Parameters:

  • action_id (Symbol)
  • interaction_klass (Class)
  • handler_name: (String, nil) (defaults to: nil)


115
116
117
118
119
# File 'lib/slack_bot/config.rb', line 115

def block_action(action_id, interaction_klass, handler_name: nil)
  @block_actions ||= {}
  @block_actions[action_id.to_sym] = interaction_klass
  interaction(interaction_klass, handler_name: handler_name)
end

#callback_storage(klass) ⇒ void

This method returns an undefined value.

Parameters:

  • klass (Object)


16
17
18
# File 'lib/slack_bot/config.rb', line 16

def callback_storage(klass)
  @callback_storage_instance = klass
end

#callback_storage!Object

Returns:

  • (Object)

Raises:



20
21
22
23
24
25
26
# File 'lib/slack_bot/config.rb', line 20

def callback_storage!
  return @callback_storage_instance if @callback_storage_instance

  raise SlackBot::Errors::ConfigurationError.new(
    "callback_storage is not configured; call SlackBot::Config.configure { |config| config.callback_storage ... }"
  )
end

#callback_user_finder(method_lambda) ⇒ void

This method returns an undefined value.

Parameters:

  • method_lambda (Proc)


29
30
31
# File 'lib/slack_bot/config.rb', line 29

def callback_user_finder(method_lambda)
  @callback_user_finder_method = method_lambda
end

#callback_user_finder!Proc

Returns:

  • (Proc)

Raises:



33
34
35
36
37
38
39
# File 'lib/slack_bot/config.rb', line 33

def callback_user_finder!
  return @callback_user_finder_method if @callback_user_finder_method

  raise SlackBot::Errors::ConfigurationError.new(
    "callback_user_finder is not configured; call SlackBot::Config.configure { |config| config.callback_user_finder ... }"
  )
end

#event(event_type, event_klass, handler_name: nil) ⇒ void

This method returns an undefined value.

Parameters:

  • event_type (Symbol)
  • event_klass (Class)
  • handler_name: (String, nil) (defaults to: nil)


68
69
70
71
72
# File 'lib/slack_bot/config.rb', line 68

def event(event_type, event_klass, handler_name: nil)
  handler_name ||= event_klass.name
  handler_class(handler_name, event_klass)
  event_handlers[event_type.to_sym] = event_klass
end

#event_dispatcher(method_lambda) ⇒ void

This method returns an undefined value.

Parameters:

  • method_lambda (Proc)


55
56
57
# File 'lib/slack_bot/config.rb', line 55

def event_dispatcher(method_lambda)
  @event_dispatcher_method = method_lambda
end

#event_handlersHash[Symbol, Class]

Returns:

  • (Hash[Symbol, Class])


64
65
66
# File 'lib/slack_bot/config.rb', line 64

def event_handlers
  @event_handlers ||= {}
end

#find_block_action(action_id) ⇒ Class?

Parameters:

  • action_id (Symbol)

Returns:

  • (Class, nil)


121
122
123
124
# File 'lib/slack_bot/config.rb', line 121

def find_block_action(action_id)
  @block_actions ||= {}
  @block_actions[action_id.to_sym]
end

#find_event_handler(event_type) ⇒ Class?

Parameters:

  • event_type (Symbol)

Returns:

  • (Class, nil)


74
75
76
# File 'lib/slack_bot/config.rb', line 74

def find_event_handler(event_type)
  event_handlers[event_type.to_sym]
end

#find_handler_class(class_name) ⇒ Class

Parameters:

  • class_name (String)

Returns:

  • (Class)


133
134
135
136
137
138
139
140
# File 'lib/slack_bot/config.rb', line 133

def find_handler_class(class_name)
  @handler_classes ||= {}
  return if class_name.nil?

  @handler_classes.fetch(class_name.to_sym)
rescue KeyError
  raise SlackBot::Errors::HandlerClassNotFound.new(class_name, handler_classes: @handler_classes)
end

#find_menu_options(action_id) ⇒ Class?

Parameters:

  • action_id (Symbol)

Returns:

  • (Class, nil)


110
111
112
113
# File 'lib/slack_bot/config.rb', line 110

def find_menu_options(action_id)
  @menu_options ||= {}
  @menu_options[action_id.to_sym]
end

#find_slash_command_config(url_token, command, text) ⇒ SlashCommandConfig?

Parameters:

  • url_token (Symbol)
  • command (String)
  • text (String)

Returns:



98
99
100
101
102
103
# File 'lib/slack_bot/config.rb', line 98

def find_slash_command_config(url_token, command, text)
  endpoint_config = slash_command_endpoints[url_token.to_sym]
  return if endpoint_config.blank?

  endpoint_config.find_command_config(text) || endpoint_config
end

#handler_class(class_name, klass) ⇒ void

This method returns an undefined value.

Parameters:

  • class_name (String)
  • klass (Class)


126
127
128
129
130
131
# File 'lib/slack_bot/config.rb', line 126

def handler_class(class_name, klass)
  @handler_classes ||= {}
  return if class_name.nil?

  @handler_classes[class_name.to_sym] = klass
end

#interaction(interaction_klass, handler_name: nil) ⇒ void

This method returns an undefined value.

Parameters:

  • interaction_klass (Class)
  • handler_name: (String, nil) (defaults to: nil)


59
60
61
62
# File 'lib/slack_bot/config.rb', line 59

def interaction(interaction_klass, handler_name: nil)
  handler_name ||= interaction_klass.name
  handler_class(handler_name, interaction_klass)
end

This method returns an undefined value.

Parameters:

  • action_id (Symbol)
  • klass (Class)


105
106
107
108
# File 'lib/slack_bot/config.rb', line 105

def menu_options(action_id, klass)
  @menu_options ||= {}
  @menu_options[action_id.to_sym] = klass
end

#slash_command_endpoint(url_token, command_klass = nil, handler_name: nil) {|arg0| ... } ⇒ SlashCommandEndpointConfig

Parameters:

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

Yields:

Yield Parameters:

Yield Returns:

  • (void)

Returns:



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/slack_bot/config.rb', line 78

def slash_command_endpoint(url_token, command_klass = nil, handler_name: nil, &)
  @slash_command_endpoints ||= {}
  @slash_command_endpoints[url_token.to_sym] ||=
    begin
      endpoint =
        SlashCommandEndpointConfig.new(
          url_token,
          command_klass: command_klass,
          config: self,
          handler_name: handler_name
        )
      endpoint.instance_eval(&) if block_given?
      endpoint
    end
end

#slash_command_endpointsHash[Symbol, SlashCommandEndpointConfig]

Returns:



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

def slash_command_endpoints
  @slash_command_endpoints ||= {}
end

#user_session_resolver(method_lambda) ⇒ void

This method returns an undefined value.

Parameters:

  • method_lambda (Proc)


42
43
44
# File 'lib/slack_bot/config.rb', line 42

def user_session_resolver(method_lambda)
  @user_session_resolver_method = method_lambda
end

#user_session_resolver!Proc

Returns:

  • (Proc)

Raises:



46
47
48
49
50
51
52
# File 'lib/slack_bot/config.rb', line 46

def user_session_resolver!
  return @user_session_resolver_method if @user_session_resolver_method

  raise SlackBot::Errors::ConfigurationError.new(
    "user_session_resolver is not configured; call SlackBot::Config.configure { |config| config.user_session_resolver ... }"
  )
end