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

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

Overview

Stores everything.

Instance Attribute Summary

Attributes inherited from Base

#bots, #channels, #groups, #ims, #teams, #users

Instance Method Summary collapse

Methods inherited from Base

on

Constructor Details

#initialize(attrs) ⇒ Store

Returns a new instance of Store.



15
16
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
49
50
51
52
53
54
# File 'lib/slack/real_time/stores/store.rb', line 15

def initialize(attrs)
  if attrs.team
    @team_id = attrs.team.id
    @teams = { @team_id => Slack::RealTime::Models::Team.new(attrs.team) }
  else
    @teams = {}
  end

  if attrs.self
    @self_id = attrs.self.id
    @users = { @self_id => Slack::RealTime::Models::User.new(attrs.self) }
  else
    @users = {}
  end

  attrs.users&.each do |data|
    user = Models::User.new(data)
    @users[data.id] = @users.key?(data.id) ? @users[data.id].merge(user) : user
  end

  @channels = {}
  attrs.channels&.each do |data|
    @channels[data.id] = Models::Channel.new(data)
  end

  @bots = {}
  attrs.bots&.each do |data|
    @bots[data.id] = Models::Bot.new(data)
  end

  @groups = {}
  attrs.groups&.each do |data|
    @groups[data.id] = Models::Group.new(data)
  end

  @ims = {}
  attrs.ims&.each do |data|
    @ims[data.id] = Models::Im.new(data)
  end
end

Instance Method Details

#selfObject



7
8
9
# File 'lib/slack/real_time/stores/store.rb', line 7

def self
  users[@self_id]
end

#teamObject



11
12
13
# File 'lib/slack/real_time/stores/store.rb', line 11

def team
  teams[@team_id]
end