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.
6 7 8 |
# File 'lib/resource_kit/resource_collection.rb', line 6 def initialize @collection = [] end |
Instance Method Details
#action(name, verb_and_path = nil, &block) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/resource_kit/resource_collection.rb', line 10 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
17 18 19 20 21 22 23 24 |
# File 'lib/resource_kit/resource_collection.rb', line 17 def default_handler(*response_codes, &block) response_codes.each do |code| unless code.is_a?(Fixnum) code = StatusCodeMapper.code_for(code) end default_handlers[code] = block end end |
#default_handlers ⇒ Object
26 27 28 |
# File 'lib/resource_kit/resource_collection.rb', line 26 def default_handlers @default_handlers ||= {} end |
#find_action(name) ⇒ Object
30 31 32 33 34 |
# File 'lib/resource_kit/resource_collection.rb', line 30 def find_action(name) find do |action| action.name == name end end |