Class: SlackBot::Config

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

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.



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

def callback_storage_instance
  @callback_storage_instance
end

#callback_user_finder_methodObject (readonly)

Returns the value of attribute callback_user_finder_method.



20
21
22
# File 'lib/slack_bot/config.rb', line 20

def callback_user_finder_method
  @callback_user_finder_method
end

Class Method Details

.configureObject



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

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

.current_instanceObject



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

#callback_storage(klass) ⇒ Object



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

def callback_storage(klass)
  @callback_storage_instance = klass
end

#callback_user_finder(method_lambda) ⇒ Object



21
22
23
# File 'lib/slack_bot/config.rb', line 21

def callback_user_finder(method_lambda)
  @callback_user_finder_method = method_lambda
end

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



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

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_handlersObject



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

def event_handlers
  @event_handlers ||= {}
end

#find_event_handler(event_type) ⇒ Object



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

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

#find_handler_class(class_name) ⇒ Object



86
87
88
89
90
91
# File 'lib/slack_bot/config.rb', line 86

def find_handler_class(class_name)
  @handler_classes ||= {}
  @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) ⇒ Object



76
77
78
79
# File 'lib/slack_bot/config.rb', line 76

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

#find_slash_command_config(url_token, command, text) ⇒ Object



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

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) ⇒ Object



81
82
83
84
# File 'lib/slack_bot/config.rb', line 81

def handler_class(class_name, klass)
  @handler_classes ||= {}
  @handler_classes[class_name.to_sym] = klass
end

#interaction(interaction_klass, handler_name: nil) ⇒ Object



25
26
27
28
# File 'lib/slack_bot/config.rb', line 25

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


71
72
73
74
# File 'lib/slack_bot/config.rb', line 71

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) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/slack_bot/config.rb', line 44

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_endpointsObject



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

def slash_command_endpoints
  @slash_command_endpoints ||= {}
end