Class: Slack::RealTime::Store

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Store

Returns a new instance of Store


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
# File 'lib/slack/real_time/store.rb', line 19

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

  {
    'users' => Models::User,
    'channels' => Models::Channel,
    'bots' => Models::Bot,
    'groups' => Models::Group,
    'ims' => Models::Im
  }.each_pair do |key, klass|
    instance_variable_set "@#{key}", {}
    attrs[key].each do |data|
      instance_variable_get("@#{key}").send(:[]=, data.id, klass.new(data))
    end if attrs.key?(key)
  end

  if attrs.self
    @self_id = attrs.self.id
    @users[@self_id].merge!(attrs.self)
  end
end

Instance Attribute Details

#botsObject

Returns the value of attribute bots


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

def bots
  @bots
end

#channelsObject

Returns the value of attribute channels


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

def channels
  @channels
end

#groupsObject

Returns the value of attribute groups


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

def groups
  @groups
end

#imsObject

Returns the value of attribute ims


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

def ims
  @ims
end

#teamsObject

Returns the value of attribute teams


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

def teams
  @teams
end

#usersObject

Returns the value of attribute users


4
5
6
# File 'lib/slack/real_time/store.rb', line 4

def users
  @users
end

Instance Method Details

#selfObject


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

def self
  users[@self_id]
end

#teamObject


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

def team
  teams[@team_id]
end