Class: Toot::Config

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

Instance Method Summary collapse

Instance Method Details

#find_source_by_name(name) ⇒ Object



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

def find_source_by_name(name)
  sources.find { |source| source.name == name }
end

#http_connectionObject



49
50
51
# File 'lib/toot/config.rb', line 49

def http_connection
  self[:http_connection] ||= Faraday::Connection.new
end

#redis_connectionObject



53
54
55
# File 'lib/toot/config.rb', line 53

def redis_connection
  self[:redis_connection] ||= Sidekiq.method(:redis)
end

#source(name, subscription_url:, channel_prefix:) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/toot/config.rb', line 11

def source(name, subscription_url:, channel_prefix:)
  Source.new(
    name: name,
    subscription_url: subscription_url,
    channel_prefix: channel_prefix
  ).tap do |source|
    sources << source
  end
end

#sourcesObject



33
34
35
# File 'lib/toot/config.rb', line 33

def sources
  @sources ||= []
end

#subscribe(source_name, channel_suffix, handler) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/toot/config.rb', line 21

def subscribe(source_name, channel_suffix, handler)
  source = find_source_by_name(source_name) or
    fail(ConfigError, "You cannot subscribe to an undefined source: #{source_name}")
  Subscription.new(
    source: source,
    channel: [source.channel_prefix, channel_suffix].join,
    handler: handler
  ).tap do |subscription|
    subscriptions << subscription
  end
end

#subscriptionsObject



37
38
39
# File 'lib/toot/config.rb', line 37

def subscriptions
  @subscriptions ||= []
end

#subscriptions_for_channel(channel) ⇒ Object



45
46
47
# File 'lib/toot/config.rb', line 45

def subscriptions_for_channel(channel)
  subscriptions.select { |s| s.channel == channel }
end