Class: Slack::RealTime::Stores::Store

Inherits:
Base
  • Object
show all
Defined in:
lib/slack/real_time/stores/store.rb

Overview

Full store with initialization logic

Constant Summary collapse

CONVERSATION_TYPES =
{
  public_channels: 'public_channel',
  private_channels: 'private_channel',
  ims: 'im',
  mpims: 'mpim'
}.freeze

Constants inherited from Base

Base::CACHES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited, on

Constructor Details

#initialize(attrs, options = {}) ⇒ Store

Returns a new instance of Store.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/slack/real_time/stores/store.rb', line 17

def initialize(attrs, options = {})
  @teams = {}
  @users = {}
  @bots = {}
  @public_channels = {}
  @private_channels = {}
  @ims = {}
  @mpims = {}

  if attrs.team
    @team_id = attrs.team.id
    @teams[@team_id] = Models::Team.new(attrs.team)
  end

  if attrs.self
    @self_id = attrs.self.id
    @users[@self_id] = Models::User.new(attrs.self)
  end

  @caches =
    if options[:caches].is_a?(Array) || options[:caches].nil?
      caches = options[:caches].to_a.map(&:to_sym)
      unknown_caches = caches - CACHES
      raise ArgumentError, "Unknown caches: #{unknown_caches.join(', ')}" unless unknown_caches.empty?

      Set.new(caches).freeze
    elsif options[:caches] == :all
      Set.new(CACHES).freeze
    else
      raise ArgumentError, 'Unexpected value for option `caches`. Expects :all or an array of caches'
    end
end

Instance Attribute Details

#cachesObject (readonly)

Returns the value of attribute caches.



15
16
17
# File 'lib/slack/real_time/stores/store.rb', line 15

def caches
  @caches
end

Instance Method Details

#selfObject



50
51
52
# File 'lib/slack/real_time/stores/store.rb', line 50

def self
  users[@self_id]
end

#teamObject



54
55
56
# File 'lib/slack/real_time/stores/store.rb', line 54

def team
  teams[@team_id]
end