Class: Apipie::Extractor::Writer
- Inherits:
-
Object
- Object
- Apipie::Extractor::Writer
- Defined in:
- lib/apipie/extractor/writer.rb
Class Method Summary collapse
- .compressed ⇒ Object
- .examples_file ⇒ Object
- .load_recorded_examples ⇒ Object
- .update_action_description(controller, action) ⇒ Object
- .write_recorded_examples(examples) ⇒ Object
Instance Method Summary collapse
-
#initialize(collector) ⇒ Writer
constructor
A new instance of Writer.
- #write_docs ⇒ Object
- #write_examples ⇒ Object
Constructor Details
#initialize(collector) ⇒ Writer
Returns a new instance of Writer.
71 72 73 |
# File 'lib/apipie/extractor/writer.rb', line 71 def initialize(collector) @collector = collector end |
Class Method Details
.compressed ⇒ Object
7 8 9 |
# File 'lib/apipie/extractor/writer.rb', line 7 def compressed Apipie.configuration.compress_examples end |
.examples_file ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/apipie/extractor/writer.rb', line 33 def examples_file pure_path = Rails.root.join( Apipie.configuration.doc_path, 'apipie_examples.json' ) zipped_path = pure_path.to_s + '.gz' return zipped_path if compressed pure_path.to_s end |
.load_recorded_examples ⇒ Object
28 29 30 31 |
# File 'lib/apipie/extractor/writer.rb', line 28 def load_recorded_examples return {} unless File.exist?(examples_file) load_json_examples end |
.update_action_description(controller, action) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/apipie/extractor/writer.rb', line 11 def update_action_description(controller, action) updater = ActionDescriptionUpdater.new(controller, action) yield updater updater.write! rescue ActionDescriptionUpdater::ControllerNotFound logger.warn("REST_API: Couldn't find controller file for #{controller}") rescue ActionDescriptionUpdater::ActionNotFound logger.warn("REST_API: Couldn't find action #{action} in #{controller}") end |
.write_recorded_examples(examples) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/apipie/extractor/writer.rb', line 21 def write_recorded_examples(examples) FileUtils.mkdir_p(File.dirname(examples_file)) content = serialize_examples(examples) content = Zlib::Deflate.deflate(content).force_encoding('utf-8') if compressed File.open(examples_file, 'w') { |f| f << content } end |
Instance Method Details
#write_docs ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/apipie/extractor/writer.rb', line 81 def write_docs descriptions = @collector.finalize_descriptions descriptions.each_value do |desc| if desc[:api].empty? logger.warn("REST_API: Couldn't find any path for #{desc_to_s(desc)}") next end self.class.update_action_description(desc[:controller], desc[:action]) do |u| u.update_generated_description desc end end end |
#write_examples ⇒ Object
76 77 78 79 |
# File 'lib/apipie/extractor/writer.rb', line 76 def write_examples merged_examples = merge_old_new_examples self.class.write_recorded_examples(merged_examples) end |