Class: Hipmost::Hipchat::RoomRepository

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/hipmost/hipchat/room_repository.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ RoomRepository

Returns a new instance of RoomRepository.



17
18
19
20
21
# File 'lib/hipmost/hipchat/room_repository.rb', line 17

def initialize(path)
  @path  = Pathname.new(path).join("rooms.json")
  @rooms = {}
  @name_index = {}
end

Instance Attribute Details

#name_indexObject

Returns the value of attribute name_index.



8
9
10
# File 'lib/hipmost/hipchat/room_repository.rb', line 8

def name_index
  @name_index
end

#roomsObject

Returns the value of attribute rooms.



8
9
10
# File 'lib/hipmost/hipchat/room_repository.rb', line 8

def rooms
  @rooms
end

Class Method Details

.load_from(path) ⇒ Object



13
14
15
# File 'lib/hipmost/hipchat/room_repository.rb', line 13

def self.load_from(path)
  new(path).tap(&:load)
end

Instance Method Details

#file_dataObject



37
38
39
40
41
42
43
# File 'lib/hipmost/hipchat/room_repository.rb', line 37

def file_data
  if File.exists? @path
    File.read(@path)
  else
    abort "./data does not exist; did you forget to specify a path to the data?"
  end
end

#find_by_name(name) ⇒ Object



33
34
35
# File 'lib/hipmost/hipchat/room_repository.rb', line 33

def find_by_name(name)
  self[name_index[name]]
end

#load(data = file_data) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/hipmost/hipchat/room_repository.rb', line 23

def load(data = file_data)
  json = JSON.load(data)

  json.each do |room_obj|
    room = room_obj["Room"]
    @rooms[room["id"]] = Room.new(room)
    @name_index[room["name"]] = room["id"]
  end
end