Class: ResourceKit::ResourceCollection
- Inherits:
-
Object
- Object
- ResourceKit::ResourceCollection
- Extended by:
- Forwardable
- Defined in:
- lib/resource_kit/resource_collection.rb
Instance Method Summary collapse
- #action(name, verb_and_path = nil, &block) ⇒ Object
- #default_handler(*response_codes, &block) ⇒ Object
- #default_handlers ⇒ Object
- #find_action(name) ⇒ Object
-
#initialize ⇒ ResourceCollection
constructor
A new instance of ResourceCollection.
Constructor Details
#initialize ⇒ ResourceCollection
Returns a new instance of ResourceCollection.
8 9 10 |
# File 'lib/resource_kit/resource_collection.rb', line 8 def initialize @collection = [] end |
Instance Method Details
#action(name, verb_and_path = nil, &block) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/resource_kit/resource_collection.rb', line 12 def action(name, verb_and_path = nil, &block) action = Action.new(name, *parse_verb_and_path(verb_and_path)) action.handlers.merge!(default_handlers.dup) action.instance_eval(&block) if block_given? action.tap { |a| self << a } end |
#default_handler(*response_codes, &block) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/resource_kit/resource_collection.rb', line 26 def default_handler(*response_codes, &block) if response_codes.empty? default_handlers[:any] = block else response_codes.each do |code| code = StatusCodeMapper.code_for(code) unless code.is_a?(Integer) default_handlers[code] = block end end end |
#default_handlers ⇒ Object
37 38 39 |
# File 'lib/resource_kit/resource_collection.rb', line 37 def default_handlers @default_handlers ||= {} end |
#find_action(name) ⇒ Object
41 42 43 44 45 |
# File 'lib/resource_kit/resource_collection.rb', line 41 def find_action(name) find do |action| action.name == name end end |