Class: HTTPalooza::Lineup

Inherits:
Object
  • Object
show all
Includes:
API
Defined in:
lib/httpalooza/lineup.rb

Constant Summary collapse

UNINVITE_REGEX =
/^(uninvite|but|not|except|without|save|besides?|minus|barring|excluding|omitting|exempting|other_than|apart_from|aside_from)_(.+)/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from API

#delete, #get, #head, #post, #put

Constructor Details

#initializeLineup

Returns a new instance of Lineup.



9
10
11
# File 'lib/httpalooza/lineup.rb', line 9

def initialize
  @players = Set.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &blk) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/httpalooza/lineup.rb', line 25

def method_missing(name, *args, &blk)
  if uninvite = UNINVITE_REGEX.match(name)
    name = uninvite.captures.second
  end

  matched_players = Players.available.select do |player|
    name.to_s.include?(player.name.to_s)
  end

  return super(name, *args, &blk) if matched_players.empty?

  if uninvite
    players.subtract(matched_players)
  else
    players.merge(matched_players)
  end

  self
end

Instance Attribute Details

#playersObject (readonly)

Returns the value of attribute players.



7
8
9
# File 'lib/httpalooza/lineup.rb', line 7

def players
  @players
end

Instance Method Details

#everyoneObject



20
21
22
23
# File 'lib/httpalooza/lineup.rb', line 20

def everyone
  players.merge(Players.available)
  self
end

#run!(request) ⇒ Object



13
14
15
16
17
18
# File 'lib/httpalooza/lineup.rb', line 13

def run!(request)
  players.inject({}) do |responses, player|
    responses[player.name] = player.execute!(request)
    responses
  end
end