From ce31d83e8c7f509ace58af1ae99be0731f115cc3 Mon Sep 17 00:00:00 2001 From: ivobenedito Date: Mon, 28 Jan 2013 16:28:32 +0000 Subject: [PATCH 1/5] implemented config file with active_support/configurable --- lib/api_taster.rb | 1 + lib/api_taster/config.rb | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 lib/api_taster/config.rb diff --git a/lib/api_taster.rb b/lib/api_taster.rb index 7add34f..5b0f7e8 100644 --- a/lib/api_taster.rb +++ b/lib/api_taster.rb @@ -2,6 +2,7 @@ require 'bootstrap-sass' require 'remotipart' require 'active_support/dependencies' +require 'api_taster/config' require 'api_taster/engine' require 'api_taster/route' require 'api_taster/mapper' diff --git a/lib/api_taster/config.rb b/lib/api_taster/config.rb new file mode 100644 index 0000000..32cbf71 --- /dev/null +++ b/lib/api_taster/config.rb @@ -0,0 +1,39 @@ +require 'active_support/configurable' + +module ApiTaster + # Configures global settings for ApiTaster + # ApiTaster.configure do |config| + # config.title = 'My Application Name' + # end + def self.configure(&block) + yield @config ||= ApiTaster::Configuration.new + end + + # Global settings for ApiTaster + def self.config + @config + end + + class Configuration + include ActiveSupport::Configurable + + config_accessor :title + config_accessor :include_missing_definitions + config_accessor :include_obsolete_definitions + + def param_name + config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name + end + + # define param_name writer (copied from AS::Configurable) + writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__ + singleton_class.class_eval writer, __FILE__, line + class_eval writer, __FILE__, line + end + + configure do |config| + config.title = 'API Taster' + config.include_missing_definitions = true + config.include_obsolete_definitions = true + end +end From 8cd27484f309a216b251fe364ac53e73754c17df Mon Sep 17 00:00:00 2001 From: ivobenedito Date: Mon, 28 Jan 2013 16:29:24 +0000 Subject: [PATCH 2/5] cleanup/refactor to support parameterized obsolete and missing definitions --- .../api_taster/routes_controller.rb | 11 ++++++++-- app/views/api_taster/routes/index.html.erb | 20 ++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/controllers/api_taster/routes_controller.rb b/app/controllers/api_taster/routes_controller.rb index e5d8678..414aa99 100644 --- a/app/controllers/api_taster/routes_controller.rb +++ b/app/controllers/api_taster/routes_controller.rb @@ -1,11 +1,10 @@ module ApiTaster class RoutesController < ApiTaster::ApplicationController before_filter :map_routes + helper_method :missing_definitions?, :obsolete_definitions? def index @routes = Route.grouped_routes - @has_missing_definitions = Route.missing_definitions.present? - @has_obsolete_definitions = Route.obsolete_definitions.present? end def show @@ -27,5 +26,13 @@ def obsolete_definitions def map_routes Route.map_routes end + + def missing_definitions? + Route.missing_definitions.present? && ApiTaster.config.include_missing_definitions + end + + def obsolete_definitions? + Route.obsolete_definitions.present? && ApiTaster.config.include_obsolete_definitions + end end end diff --git a/app/views/api_taster/routes/index.html.erb b/app/views/api_taster/routes/index.html.erb index 8e99942..3f574ca 100644 --- a/app/views/api_taster/routes/index.html.erb +++ b/app/views/api_taster/routes/index.html.erb @@ -2,19 +2,17 @@