Class: HTTPalooza::Lineup
- Inherits:
-
Object
- Object
- HTTPalooza::Lineup
- Includes:
- API
- Defined in:
- lib/httpalooza/lineup.rb
Overview
A Lineup assembles a set of Players to perform HTTP requests.
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
-
#players ⇒ Object
readonly
Returns the value of attribute players.
Instance Method Summary collapse
-
#everyone ⇒ Object
Return a Lineup with all available Players.
-
#initialize ⇒ Lineup
constructor
A new instance of Lineup.
- #method_missing(name, *args, &blk) ⇒ Object
- #run!(request) ⇒ Object
Methods included from API
#delete, #get, #head, #post, #put
Constructor Details
#initialize ⇒ Lineup
Returns a new instance of Lineup.
21 22 23 |
# File 'lib/httpalooza/lineup.rb', line 21 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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/httpalooza/lineup.rb', line 38 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
#players ⇒ Object (readonly)
Returns the value of attribute players.
19 20 21 |
# File 'lib/httpalooza/lineup.rb', line 19 def players @players end |
Instance Method Details
#everyone ⇒ Object
Return a Lineup with all available Players
33 34 35 36 |
# File 'lib/httpalooza/lineup.rb', line 33 def everyone players.merge(Players.available) self end |
#run!(request) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/httpalooza/lineup.rb', line 25 def run!(request) players.inject({}) do |responses, player| responses[player.name] = player.execute!(request) responses end end |