module HouseTest

The code loaded when simply requiring the gem will only load code for the client Require 'house_test/house_server' to host server

Representing House objects in 'backend' (memory)

Constants

PORT

Port for server to run at

VERSION

Attributes

houses[RW]

Public Class Methods

add(house_params = {}) click to toggle source

Add a new house according to parameters passed @return [String] Id of house just created

# File lib/house_test/house_server.rb, line 15
def add(house_params = {})
  house = Backend::House.new(house_params)
  @houses << house
  house.id
end
delete(id) click to toggle source

Delete house at id @param [Integer] id Id of house to delete @return [Integer] Id of house deleted. Nil if not found

# File lib/house_test/house_server.rb, line 42
def delete(id)
  found_house = get id
  return nil unless found_house

  houses.delete(found_house)
  id
end
descriptions() click to toggle source

@return [String] Description of all houses

# File lib/house_test/house_server.rb, line 51
def descriptions
  houses.map(&:description)
end
get(id) click to toggle source

Get an existing house @param [Integer] id Id of house to get @return [House] House found. Nil if nothing found

# File lib/house_test/house_server.rb, line 24
def get(id)
  houses.find { |house| house.id == id }
end
update(id, key, value) click to toggle source

Update house at id's key to value @param [Integer] id Id of house to update @return [Integer] Id of house updated

# File lib/house_test/house_server.rb, line 31
def update(id, key, value)
  found_house = get id
  return nil unless found_house

  found_house.send("#{key}=", value)
  id
end