lib/apipie/extractor.rb in apipie-rails-0.1.3 vs lib/apipie/extractor.rb in apipie-rails-0.2.0

- old
+ new

@@ -5,31 +5,54 @@ require 'apipie/extractor/recorder' require 'apipie/extractor/writer' require 'apipie/extractor/collector' class Apipie::Railtie - if ENV["APIPIE_RECORD"] - initializer 'apipie.extractor' do |app| - ActiveSupport.on_load :action_controller do - before_filter do |controller| + initializer 'apipie.extractor' do |app| + ActiveSupport.on_load :action_controller do + before_filter do |controller| + if Apipie.configuration.record Apipie::Extractor.call_recorder.analyse_controller(controller) end end - app.middleware.use ::Apipie::Extractor::Recorder::Middleware - ActionController::TestCase::Behavior.instance_eval do - include Apipie::Extractor::Recorder::FunctionalTestRecording - end end + app.middleware.use ::Apipie::Extractor::Recorder::Middleware + ActionController::TestCase::Behavior.instance_eval do + include Apipie::Extractor::Recorder::FunctionalTestRecording + end end end module Apipie module Extractor class << self + def start(record) + Apipie.configuration.record = record + Apipie.configuration.force_dsl = true + end + + def finish + record_params, record_examples = false, false + case Apipie.configuration.record + when "params" then record_params = true + when "examples" then record_examples = true + when "all" then record_params = true, record_examples = true + end + + if record_examples + puts "Writing examples to a file" + write_examples + end + if record_params + puts "Updating auto-generated documentation" + write_docs + end + end + def logger Rails.logger end def call_recorder @@ -142,30 +165,16 @@ new_api[:desc] = old_api[:desc] end end end end - end end end if ENV["APIPIE_RECORD"] - Apipie.configuration.force_dsl = true - at_exit do - record_params, record_examples = false, false - case ENV["APIPIE_RECORD"] - when "params" then record_params = true - when "examples" then record_examples = true - when "all" then record_params = true, record_examples = true - end + Apipie::Extractor.start ENV["APIPIE_RECORD"] +end - if record_examples - puts "Writing examples to a file" - Apipie::Extractor.write_examples - end - if record_params - puts "Updating auto-generated documentation" - Apipie::Extractor.write_docs - end - end +at_exit do + Apipie::Extractor.finish end