avocado-docs 3.1.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 123473147cc4247d7969a4915482ed62561d8dc9
4
- data.tar.gz: f50e931484bea88717cd4a15dce81719fd89d64d
3
+ metadata.gz: a53e9c7b26a64f5491ef065942a6bff4326b60fc
4
+ data.tar.gz: b3bf621f28f386052bd861def025eb6b6bfa48f9
5
5
  SHA512:
6
- metadata.gz: 49b732845e2af906c9335b13d2640070d051bd4f9bef0b8e4f2e50004de49eb11a9f3728b20cb1790cfdb97ce15e45cfa7f7d1501d8c95cd23a1c8b77579c6ed
7
- data.tar.gz: a4d06e826dc8a503d19c7ac71da6ce68c6415d5b20c19a80b8c47e9bedcf420694f330974d6855242c9ce674468ff20b96d2c001dc207ca12dc95b9e401c61d0
6
+ metadata.gz: f149da4dcfb28fc8aef10fe0b41d407449a18198aba01cafb7cb060488f0fb42bfd0e40aec133eff0a3ed83fe5448c5ad5cc3806e6c9b70c725965b3c7254db9
7
+ data.tar.gz: 840a45e77a6f6475a991f4d6d84eb1f240fe4f6c4aeef50c031323386229d776de1b15a59619a72e52bc784c4ffb537e1b6f29c0535703b548bc0b16e3306b50
@@ -3,32 +3,22 @@ module Avocado
3
3
  layout 'avocado'
4
4
 
5
5
  def index
6
- @data = json_files.map { |filename| File.read filename }
6
+ @data = storage.read
7
7
  end
8
8
 
9
9
  def create
10
- File.open(new_json_filename, 'w+') { |f| f.write params[:file].read }
11
- File.delete(*json_files_from_past_uploads)
10
+ storage.write params[:file].read, upload_id
11
+ storage.purge_old upload_id
12
12
  head :ok
13
13
  end
14
14
 
15
15
  private
16
- def upload_id
17
- params[:upload_id]
18
- end
19
-
20
- def new_json_filename
21
- Avocado.json_path.join "avocado-#{Time.current.to_s(:nsec)}-#{upload_id}.json"
16
+ def storage
17
+ Avocado.storage
22
18
  end
23
19
 
24
- def json_files
25
- Dir.glob Avocado.json_path.join('avocado*.json')
26
- end
27
-
28
- def json_files_from_past_uploads
29
- json_files.reject do |spec|
30
- spec.end_with? "-#{upload_id}.json"
31
- end
20
+ def upload_id
21
+ params[:upload_id]
32
22
  end
33
23
  end
34
24
  end
@@ -1,4 +1,4 @@
1
1
  Avocado::Engine.routes.draw do
2
- resources :specs, only: [:create]
2
+ post '/', to: 'specs#create'
3
3
  root to: 'specs#index'
4
4
  end
@@ -2,19 +2,22 @@ require 'avocado/engine'
2
2
  require 'avocado/controller_patch'
3
3
  require 'avocado/controller_response'
4
4
  require 'avocado/logger'
5
- require 'avocado/storage'
5
+ require 'avocado/cache'
6
6
  require 'avocado/uploader'
7
+ require 'avocado/storage/file'
8
+
7
9
  require 'avocado/adapters/base_adapter'
8
10
  require 'avocado/adapters/minitest_adapter'
9
11
  require 'avocado/adapters/rspec_adapter'
10
12
  require 'avocado/adapters/cucumber_adapter'
13
+
11
14
  require 'avocado/serializers/request_serializer'
12
15
  require 'avocado/serializers/resource_serializer'
13
16
  require 'avocado/serializers/response_serializer'
14
17
 
15
18
  module Avocado
16
19
  class << self
17
- attr_accessor :url, :headers, :json_path, :upload_id, :document_if, :ignored_params, :storage, :uploader
20
+ attr_accessor :url, :headers, :upload_id, :document_if, :ignored_params, :cache, :uploader, :storage
18
21
 
19
22
  def configure
20
23
  yield self
@@ -23,14 +26,14 @@ module Avocado
23
26
  def reset!
24
27
  self.url = nil
25
28
  self.headers = []
26
- self.json_path = ::Rails.root
27
29
  self.upload_id = proc { SecureRandom.uuid }
28
30
  self.document_if = proc { true }
29
31
  self.ignored_params = %w(controller action format)
30
- self.storage = Avocado::Storage.instance
32
+ self.cache = Avocado::Cache.instance
31
33
  self.uploader = Avocado::Uploader.instance
34
+ self.storage = Avocado::Storage::File.new ::Rails.root
32
35
 
33
- storage.clear
36
+ cache.clear
34
37
  uploader.reset
35
38
  end
36
39
  end
@@ -1,7 +1,7 @@
1
1
  # Temporarily store a JSON request/response. Ultimately RSpec will determine
2
2
  # if this request/response gets documented or not in an after(:each) block
3
3
  module Avocado
4
- class Storage
4
+ class Cache
5
5
  include Singleton
6
6
 
7
7
  attr_accessor :request, :response
@@ -14,7 +14,7 @@ module Avocado
14
14
  def _avocado_store_request
15
15
  yield
16
16
  ensure
17
- Avocado.storage.store(request, response) if _avocado_response.documentable?
17
+ Avocado.cache.store(request, response) if _avocado_response.documentable?
18
18
  end
19
19
 
20
20
  def _avocado_response
@@ -7,12 +7,12 @@ module Avocado::Minitest
7
7
  def before_teardown
8
8
  super
9
9
 
10
- request = Avocado.storage.request
11
- response = Avocado.storage.response
10
+ request = Avocado.cache.request
11
+ response = Avocado.cache.response
12
12
  adapter = Avocado::Adapters::MinitestAdapter.new name, request, response
13
13
 
14
14
  Avocado.uploader.payload << adapter.to_h if adapter.upload?
15
- Avocado.storage.clear
15
+ Avocado.cache.clear
16
16
  end
17
17
  end
18
18
 
@@ -7,12 +7,12 @@ RSpec.configure do |config|
7
7
  # Older versions of RSpec use the global `example` object
8
8
  spec = defined?(example) ? example : ex
9
9
 
10
- request = Avocado.storage.request
11
- response = Avocado.storage.response
10
+ request = Avocado.cache.request
11
+ response = Avocado.cache.response
12
12
  adapter = Avocado::Adapters::RSpecAdapter.new spec, request, response
13
13
 
14
14
  Avocado.uploader.payload << adapter.to_h if adapter.upload?
15
- Avocado.storage.clear
15
+ Avocado.cache.clear
16
16
  end
17
17
 
18
18
  config.after(:suite) do
@@ -0,0 +1,28 @@
1
+ module Avocado
2
+ module Storage
3
+ class File
4
+ def initialize(dir)
5
+ @dir = dir
6
+ end
7
+
8
+ def read
9
+ files.map { |filename| ::File.read filename }
10
+ end
11
+
12
+ def write(data, upload_id)
13
+ filename = @dir.join "avocado-#{Time.current.to_s(:nsec)}-#{upload_id}.json"
14
+ ::File.open(filename, 'w+') { |f| f.write data }
15
+ end
16
+
17
+ def purge_old(upload_id)
18
+ old_files = files.reject { |fn| fn.end_with? "-#{upload_id}.json" }
19
+ ::File.delete(*old_files)
20
+ end
21
+
22
+ private
23
+ def files
24
+ Dir.glob @dir.join('avocado*.json')
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Avocado
2
- VERSION = '3.1.2'.freeze
2
+ VERSION = '4.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avocado-docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.2
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logan Serman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-18 00:00:00.000000000 Z
11
+ date: 2017-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -139,6 +139,7 @@ files:
139
139
  - lib/avocado/adapters/cucumber_adapter.rb
140
140
  - lib/avocado/adapters/minitest_adapter.rb
141
141
  - lib/avocado/adapters/rspec_adapter.rb
142
+ - lib/avocado/cache.rb
142
143
  - lib/avocado/controller_patch.rb
143
144
  - lib/avocado/controller_response.rb
144
145
  - lib/avocado/cucumber.rb
@@ -149,7 +150,7 @@ files:
149
150
  - lib/avocado/serializers/request_serializer.rb
150
151
  - lib/avocado/serializers/resource_serializer.rb
151
152
  - lib/avocado/serializers/response_serializer.rb
152
- - lib/avocado/storage.rb
153
+ - lib/avocado/storage/file.rb
153
154
  - lib/avocado/uploader.rb
154
155
  - lib/avocado/version.rb
155
156
  homepage: http://github.com/metova/avocado
@@ -171,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
171
172
  version: '0'
172
173
  requirements: []
173
174
  rubyforge_project:
174
- rubygems_version: 2.6.8
175
+ rubygems_version: 2.6.11
175
176
  signing_key:
176
177
  specification_version: 4
177
178
  summary: Automatic API documentation from RSpec tests