class ResourceKit::ResourceCollection
Public Class Methods
new()
click to toggle source
# File lib/resource_kit/resource_collection.rb, line 6 def initialize @collection = [] end
Public Instance Methods
action(name, verb_and_path = nil, &block)
click to toggle source
# 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)
click to toggle source
# File lib/resource_kit/resource_collection.rb, line 24 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()
click to toggle source
# File lib/resource_kit/resource_collection.rb, line 35 def default_handlers @default_handlers ||= {} end
find_action(name)
click to toggle source
# File lib/resource_kit/resource_collection.rb, line 39 def find_action(name) find do |action| action.name == name end end
Private Instance Methods
parse_verb_and_path(verb_and_path)
click to toggle source
# File lib/resource_kit/resource_collection.rb, line 47 def parse_verb_and_path(verb_and_path) return [] unless verb_and_path regex = /(?<verb>GET|POST|HEAD|PUT|PATCH|DELETE|OPTIONS)?\s*(?<path>.+)?/i matched = verb_and_path.match(regex) return matched[:verb], matched[:path] end