From ff06d8e7fc35252a26a5e7bf7fb4ce376215899f Mon Sep 17 00:00:00 2001 From: Fred Wu Date: Fri, 19 Jul 2013 10:19:35 +1000 Subject: [PATCH] Small code clean ups --- lib/api_taster/form_builder.rb | 10 +++++----- lib/api_taster/route.rb | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/api_taster/form_builder.rb b/lib/api_taster/form_builder.rb index 7c794c6..10c8f19 100644 --- a/lib/api_taster/form_builder.rb +++ b/lib/api_taster/form_builder.rb @@ -26,15 +26,15 @@ def add_to_buffer(params, parent_labels = []) new_parent_labels = parent_labels.clone << label - if value.is_a?(Hash) + case value + when Hash add_legend_to_buffer(parent_labels, label) - add_to_buffer(value, new_parent_labels) - elsif value.is_a?(Array) + when Array value.each do |v| - if v.is_a?(Hash) + case v + when Hash add_legend_to_buffer(parent_labels, label) - add_to_buffer(v, parent_labels.clone << "#{label}[]") else add_element_to_buffer(parent_labels, "#{label}[]", v) diff --git a/lib/api_taster/route.rb b/lib/api_taster/route.rb index 521e6fb..1d12b97 100644 --- a/lib/api_taster/route.rb +++ b/lib/api_taster/route.rb @@ -38,10 +38,12 @@ def normalise_routes! next if route.app.is_a?(Sprockets::Environment) next if route.app == ApiTaster::Engine - if (rack_app = discover_rack_app(route.app)) && rack_app.respond_to?(:routes) + rack_app = discover_rack_app(route.app) + + if rack_app && rack_app.respond_to?(:routes) && rack_app.routes.respond_to?(:routes) rack_app.routes.routes.each do |rack_route| self.routes << normalise_route(rack_route, route.path.spec) - end if rack_app.routes.respond_to?(:routes) + end end next if route.verb.source.empty?