Class: Slk::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/slk/runner.rb

Overview

Dependency injection container providing services to commands rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output: nil, config: nil, token_store: nil, api_client: nil, cache_store: nil, preset_store: nil) ⇒ Runner

rubocop:disable Metrics/ParameterLists



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/slk/runner.rb', line 10

def initialize(
  output: nil,
  config: nil,
  token_store: nil,
  api_client: nil,
  cache_store: nil,
  preset_store: nil
)
  @output = output || Formatters::Output.new
  @config = config || Services::Configuration.new
  @token_store = token_store || Services::TokenStore.new(config: @config)
  @api_client = api_client || Services::ApiClient.new
  @cache_store = cache_store || Services::CacheStore.new
  @preset_store = preset_store || Services::PresetStore.new

  # Wire up warning callbacks to show warnings to users
  wire_up_warnings
end

Instance Attribute Details

#api_clientObject (readonly)

Returns the value of attribute api_client.



7
8
9
# File 'lib/slk/runner.rb', line 7

def api_client
  @api_client
end

#cache_storeObject (readonly)

Returns the value of attribute cache_store.



7
8
9
# File 'lib/slk/runner.rb', line 7

def cache_store
  @cache_store
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/slk/runner.rb', line 7

def config
  @config
end

#outputObject (readonly)

Returns the value of attribute output.



7
8
9
# File 'lib/slk/runner.rb', line 7

def output
  @output
end

#preset_storeObject (readonly)

Returns the value of attribute preset_store.



7
8
9
# File 'lib/slk/runner.rb', line 7

def preset_store
  @preset_store
end

#token_storeObject (readonly)

Returns the value of attribute token_store.



7
8
9
# File 'lib/slk/runner.rb', line 7

def token_store
  @token_store
end

Instance Method Details

#activity_api(workspace_name = nil) ⇒ Object



79
80
81
# File 'lib/slk/runner.rb', line 79

def activity_api(workspace_name = nil)
  Api::Activity.new(@api_client, workspace(workspace_name))
end

#all_workspacesObject



38
39
40
# File 'lib/slk/runner.rb', line 38

def all_workspaces
  @token_store.all_workspaces
end

#bots_api(workspace_name = nil) ⇒ Object



71
72
73
# File 'lib/slk/runner.rb', line 71

def bots_api(workspace_name = nil)
  Api::Bots.new(@api_client, workspace(workspace_name), on_debug: ->(msg) { @output.debug(msg) })
end

#client_api(workspace_name = nil) ⇒ Object



63
64
65
# File 'lib/slk/runner.rb', line 63

def client_api(workspace_name = nil)
  Api::Client.new(@api_client, workspace(workspace_name))
end

#conversations_api(workspace_name = nil) ⇒ Object



55
56
57
# File 'lib/slk/runner.rb', line 55

def conversations_api(workspace_name = nil)
  Api::Conversations.new(@api_client, workspace(workspace_name))
end

#dnd_api(workspace_name = nil) ⇒ Object



59
60
61
# File 'lib/slk/runner.rb', line 59

def dnd_api(workspace_name = nil)
  Api::Dnd.new(@api_client, workspace(workspace_name))
end

#duration_formatterObject



129
130
131
# File 'lib/slk/runner.rb', line 129

def duration_formatter
  @duration_formatter ||= Formatters::DurationFormatter.new
end

#emoji_api(workspace_name = nil) ⇒ Object



67
68
69
# File 'lib/slk/runner.rb', line 67

def emoji_api(workspace_name = nil)
  Api::Emoji.new(@api_client, workspace(workspace_name))
end

#emoji_replacerObject



118
119
120
# File 'lib/slk/runner.rb', line 118

def emoji_replacer
  @emoji_replacer ||= Formatters::EmojiReplacer.new
end

#log_error(error) ⇒ Object

Logging



142
143
144
# File 'lib/slk/runner.rb', line 142

def log_error(error)
  Support::ErrorLogger.log(error)
end

#mention_replacerObject



110
111
112
113
114
115
116
# File 'lib/slk/runner.rb', line 110

def mention_replacer
  @mention_replacer ||= Formatters::MentionReplacer.new(
    cache_store: @cache_store,
    api_client: @api_client,
    on_debug: ->(msg) { @output.debug(msg) }
  )
end

#message_formatterObject

Formatter helpers



99
100
101
102
103
104
105
106
107
108
# File 'lib/slk/runner.rb', line 99

def message_formatter
  @message_formatter ||= Formatters::MessageFormatter.new(
    output: @output,
    mention_replacer: mention_replacer,
    emoji_replacer: emoji_replacer,
    cache_store: @cache_store,
    api_client: @api_client,
    on_debug: ->(msg) { @output.debug(msg) }
  )
end

#message_resolver(workspace_name = nil) ⇒ Object



91
92
93
94
95
96
# File 'lib/slk/runner.rb', line 91

def message_resolver(workspace_name = nil)
  Services::MessageResolver.new(
    conversations_api: conversations_api(workspace_name),
    on_debug: ->(msg) { @output.debug(msg) }
  )
end

#saved_api(workspace_name = nil) ⇒ Object



87
88
89
# File 'lib/slk/runner.rb', line 87

def saved_api(workspace_name = nil)
  Api::Saved.new(@api_client, workspace(workspace_name))
end

#search_api(workspace_name = nil) ⇒ Object



83
84
85
# File 'lib/slk/runner.rb', line 83

def search_api(workspace_name = nil)
  Api::Search.new(@api_client, workspace(workspace_name))
end

#search_formatterObject



133
134
135
136
137
138
139
# File 'lib/slk/runner.rb', line 133

def search_formatter
  @search_formatter ||= Formatters::SearchFormatter.new(
    output: @output,
    mention_replacer: mention_replacer,
    text_processor: text_processor
  )
end

#text_processorObject



122
123
124
125
126
127
# File 'lib/slk/runner.rb', line 122

def text_processor
  @text_processor ||= Formatters::TextProcessor.new(
    mention_replacer: mention_replacer,
    emoji_replacer: emoji_replacer
  )
end

#threads_api(workspace_name = nil) ⇒ Object



75
76
77
# File 'lib/slk/runner.rb', line 75

def threads_api(workspace_name = nil)
  Api::Threads.new(@api_client, workspace(workspace_name))
end

#users_api(workspace_name = nil) ⇒ Object

API helpers - create API instances bound to workspace



51
52
53
# File 'lib/slk/runner.rb', line 51

def users_api(workspace_name = nil)
  Api::Users.new(@api_client, workspace(workspace_name), on_debug: ->(msg) { @output.debug(msg) })
end

#workspace(name = nil) ⇒ Object

Workspace helpers

Raises:



31
32
33
34
35
36
# File 'lib/slk/runner.rb', line 31

def workspace(name = nil)
  name ||= @config.primary_workspace
  raise ConfigError, 'No workspace specified and no primary workspace configured' unless name

  @token_store.workspace(name)
end

#workspace_namesObject



42
43
44
# File 'lib/slk/runner.rb', line 42

def workspace_names
  @token_store.workspace_names
end

#workspaces?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/slk/runner.rb', line 46

def workspaces?
  !@token_store.empty?
end