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.



14
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
55
56
57
58
59
60
61
62
63
# File 'lib/slack/real_time/stores/store.rb', line 14

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

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

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

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

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

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

Instance Method Details

#selfObject



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

def self
  users[@self_id]
end

#teamObject



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

def team
  teams[@team_id]
end