Class: Steppe::ResponderRegistry
- Inherits:
-
Object
- Object
- Steppe::ResponderRegistry
- Includes:
- Enumerable
- Defined in:
- lib/steppe/responder_registry.rb
Constant Summary collapse
- WILDCARD =
'*'
Instance Attribute Summary collapse
-
#node_name ⇒ Object
readonly
Returns the value of attribute node_name.
Instance Method Summary collapse
- #<<(responder) ⇒ Object
- #each(&block) ⇒ Object
- #freeze ⇒ Object
-
#initialize ⇒ ResponderRegistry
constructor
A new instance of ResponderRegistry.
- #resolve(response_status, accepted_content_types) ⇒ Object
Constructor Details
#initialize ⇒ ResponderRegistry
Returns a new instance of ResponderRegistry.
14 15 16 17 |
# File 'lib/steppe/responder_registry.rb', line 14 def initialize @map = {} @node_name = :responders end |
Instance Attribute Details
#node_name ⇒ Object (readonly)
Returns the value of attribute node_name.
12 13 14 |
# File 'lib/steppe/responder_registry.rb', line 12 def node_name @node_name end |
Instance Method Details
#<<(responder) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/steppe/responder_registry.rb', line 25 def <<(responder) accepts = responder.accepts @map[accepts.type] ||= {} @map[accepts.type][accepts.subtype] ||= StatusMap.new @map[accepts.type][accepts.subtype] << responder self end |
#each(&block) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/steppe/responder_registry.rb', line 33 def each(&block) return enum_for(:each) unless block_given? @map.each_value do |subtype_map| subtype_map.each_value do |status_map| status_map.each(&block) end end end |
#freeze ⇒ Object
19 20 21 22 23 |
# File 'lib/steppe/responder_registry.rb', line 19 def freeze @map.each_value(&:freeze) @map.freeze super end |
#resolve(response_status, accepted_content_types) ⇒ Object
43 44 45 46 47 |
# File 'lib/steppe/responder_registry.rb', line 43 def resolve(response_status, accepted_content_types) content_types = ContentType.parse_accept(accepted_content_types) status_map = find_status_map(content_types) status_map&.find(response_status.to_i) end |