betterdocs 0.11.0 → 0.12.1

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
  SHA256:
3
- metadata.gz: ad6f53d72b6b1dc91c3464a277c97992814fcc8b34a55f1fd043ace97b58c27a
4
- data.tar.gz: '0259b534dece36526365a0861d2750c5ac5c5446e24920ef4113f67d4f00103a'
3
+ metadata.gz: 757a9d16bec936883eec375dd7174cd01d0be5a367a082742ea466992dd8c1cf
4
+ data.tar.gz: 4f3fdf944921a32d8fae46f35f361b03c6e53e6053b72e079f2bef43a2cdfd24
5
5
  SHA512:
6
- metadata.gz: 8489c381f2cff832c4552f109f05c15fe092b95ea688025e98ef987ea4c714425dd981897b177ad6ad49d046c3166b20fb1cf10ac517a564373ca8080172fc89
7
- data.tar.gz: a9858527e935a0ed22f82f218907a4010ad86a523de7504afa55890bc4dfed66a00347cec4f0ebe0aa7dd8587ec43cee441623bb874ae2686e86316a11725c06
6
+ metadata.gz: a343976b81bbc7388aad0bf35addee30860d41f65eca0f8aa4588567ed6e7318ec3a80da3e766211d535639910fe5c367892f020ede993feca1c18bd3054015e
7
+ data.tar.gz: bd54ff6b0ea1339dfbad969588abf99596e8ba6154738a851f48cd309f3011982d9ef7736f8600bdce7b475d71caf1121768fb8c3c1971f12ecaad2e274ab6e2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.0
1
+ 0.12.1
data/betterdocs.gemspec CHANGED
@@ -1,18 +1,18 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: betterdocs 0.11.0 ruby lib
2
+ # stub: betterdocs 0.12.1 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "betterdocs".freeze
6
- s.version = "0.11.0"
6
+ s.version = "0.12.1"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["betterplace Developers".freeze]
11
- s.date = "2022-12-07"
11
+ s.date = "2022-12-09"
12
12
  s.description = "This library provides tools to generate API documention for a web site's REST-ful JSON API.".freeze
13
13
  s.email = "developers@betterplace.org".freeze
14
- s.extra_rdoc_files = ["README.md".freeze, "lib/betterdocs.rb".freeze, "lib/betterdocs/controller_collector.rb".freeze, "lib/betterdocs/dsl.rb".freeze, "lib/betterdocs/dsl/common.rb".freeze, "lib/betterdocs/dsl/controller.rb".freeze, "lib/betterdocs/dsl/controller/action.rb".freeze, "lib/betterdocs/dsl/controller/action/param.rb".freeze, "lib/betterdocs/dsl/controller/action/response.rb".freeze, "lib/betterdocs/dsl/controller/controller.rb".freeze, "lib/betterdocs/dsl/controller/controller_base.rb".freeze, "lib/betterdocs/dsl/json_params.rb".freeze, "lib/betterdocs/dsl/json_params/param.rb".freeze, "lib/betterdocs/dsl/json_type_mapper.rb".freeze, "lib/betterdocs/dsl/naming.rb".freeze, "lib/betterdocs/dsl/representer.rb".freeze, "lib/betterdocs/dsl/result.rb".freeze, "lib/betterdocs/dsl/result/collection_property.rb".freeze, "lib/betterdocs/dsl/result/link.rb".freeze, "lib/betterdocs/dsl/result/property.rb".freeze, "lib/betterdocs/generator/config_shortcuts.rb".freeze, "lib/betterdocs/generator/markdown.rb".freeze, "lib/betterdocs/generator/swagger.rb".freeze, "lib/betterdocs/global.rb".freeze, "lib/betterdocs/json_params_representer.rb".freeze, "lib/betterdocs/json_params_representer_collector.rb".freeze, "lib/betterdocs/json_time_with_zone.rb".freeze, "lib/betterdocs/mix_into_controller.rb".freeze, "lib/betterdocs/railtie.rb".freeze, "lib/betterdocs/rake_tasks.rb".freeze, "lib/betterdocs/representer.rb".freeze, "lib/betterdocs/result_representer.rb".freeze, "lib/betterdocs/result_representer_collector.rb".freeze, "lib/betterdocs/sanitizer.rb".freeze, "lib/betterdocs/section.rb".freeze, "lib/betterdocs/version.rb".freeze]
15
- s.files = [".codeclimate.yml".freeze, ".gitignore".freeze, ".rspec".freeze, ".semaphore/semaphore.yml".freeze, ".tool-versions".freeze, ".vscode/settings.json".freeze, "COPYING".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "betterdocs.gemspec".freeze, "lib/betterdocs.rb".freeze, "lib/betterdocs/controller_collector.rb".freeze, "lib/betterdocs/dsl.rb".freeze, "lib/betterdocs/dsl/common.rb".freeze, "lib/betterdocs/dsl/controller.rb".freeze, "lib/betterdocs/dsl/controller/action.rb".freeze, "lib/betterdocs/dsl/controller/action/param.rb".freeze, "lib/betterdocs/dsl/controller/action/response.rb".freeze, "lib/betterdocs/dsl/controller/controller.rb".freeze, "lib/betterdocs/dsl/controller/controller_base.rb".freeze, "lib/betterdocs/dsl/json_params.rb".freeze, "lib/betterdocs/dsl/json_params/param.rb".freeze, "lib/betterdocs/dsl/json_type_mapper.rb".freeze, "lib/betterdocs/dsl/naming.rb".freeze, "lib/betterdocs/dsl/representer.rb".freeze, "lib/betterdocs/dsl/result.rb".freeze, "lib/betterdocs/dsl/result/collection_property.rb".freeze, "lib/betterdocs/dsl/result/link.rb".freeze, "lib/betterdocs/dsl/result/property.rb".freeze, "lib/betterdocs/generator/config_shortcuts.rb".freeze, "lib/betterdocs/generator/markdown.rb".freeze, "lib/betterdocs/generator/markdown/templates/README.md.erb".freeze, "lib/betterdocs/generator/markdown/templates/section.md.erb".freeze, "lib/betterdocs/generator/swagger.rb".freeze, "lib/betterdocs/generator/swagger_static/index.html".freeze, "lib/betterdocs/global.rb".freeze, "lib/betterdocs/json_params_representer.rb".freeze, "lib/betterdocs/json_params_representer_collector.rb".freeze, "lib/betterdocs/json_time_with_zone.rb".freeze, "lib/betterdocs/mix_into_controller.rb".freeze, "lib/betterdocs/railtie.rb".freeze, "lib/betterdocs/rake_tasks.rb".freeze, "lib/betterdocs/representer.rb".freeze, "lib/betterdocs/result_representer.rb".freeze, "lib/betterdocs/result_representer_collector.rb".freeze, "lib/betterdocs/sanitizer.rb".freeze, "lib/betterdocs/section.rb".freeze, "lib/betterdocs/tasks/doc.rake".freeze, "lib/betterdocs/version.rb".freeze, "spec/assets/app/assets/images/logos/logo.png".freeze, "spec/assets/app/controllers/api/foos_controller.rb".freeze, "spec/assets/app/views/api_v4/documentation/assets/CHANGELOG.md".freeze, "spec/assets/config/betterdocs.yml".freeze, "spec/betterdocs/dsl/controller/action/param_spec.rb".freeze, "spec/betterdocs/dsl/controller/action/response_spec.rb".freeze, "spec/betterdocs/dsl/json_type_mapper_spec.rb".freeze, "spec/betterdocs/dsl/result/collection_property_spec.rb".freeze, "spec/betterdocs/dsl/result/link_spec.rb".freeze, "spec/betterdocs/dsl/result/property_spec.rb".freeze, "spec/betterdocs/generator/markdown_spec.rb".freeze, "spec/betterdocs/global_spec.rb".freeze, "spec/betterdocs/json_params_representer_spec.rb".freeze, "spec/betterdocs/result_representer_spec.rb".freeze, "spec/betterdocs/sanitizer_spec.rb".freeze, "spec/controller_dsl_spec.rb".freeze, "spec/result_representer_dsl_spec.rb".freeze, "spec/spec_helper.rb".freeze]
14
+ s.extra_rdoc_files = ["README.md".freeze, "lib/betterdocs.rb".freeze, "lib/betterdocs/controller_collector.rb".freeze, "lib/betterdocs/dsl.rb".freeze, "lib/betterdocs/dsl/common.rb".freeze, "lib/betterdocs/dsl/controller.rb".freeze, "lib/betterdocs/dsl/controller/action.rb".freeze, "lib/betterdocs/dsl/controller/action/param.rb".freeze, "lib/betterdocs/dsl/controller/action/response.rb".freeze, "lib/betterdocs/dsl/controller/controller.rb".freeze, "lib/betterdocs/dsl/controller/controller_base.rb".freeze, "lib/betterdocs/dsl/json_params.rb".freeze, "lib/betterdocs/dsl/json_params/param.rb".freeze, "lib/betterdocs/dsl/json_type_mapper.rb".freeze, "lib/betterdocs/dsl/naming.rb".freeze, "lib/betterdocs/dsl/representer.rb".freeze, "lib/betterdocs/dsl/result.rb".freeze, "lib/betterdocs/dsl/result/collection_property.rb".freeze, "lib/betterdocs/dsl/result/link.rb".freeze, "lib/betterdocs/dsl/result/property.rb".freeze, "lib/betterdocs/generator/config_shortcuts.rb".freeze, "lib/betterdocs/generator/markdown.rb".freeze, "lib/betterdocs/generator/swagger.rb".freeze, "lib/betterdocs/global.rb".freeze, "lib/betterdocs/json_params_representer.rb".freeze, "lib/betterdocs/json_params_representer_collector.rb".freeze, "lib/betterdocs/json_time_with_zone.rb".freeze, "lib/betterdocs/mix_into_controller.rb".freeze, "lib/betterdocs/railtie.rb".freeze, "lib/betterdocs/rake_tasks.rb".freeze, "lib/betterdocs/representer.rb".freeze, "lib/betterdocs/responding.rb".freeze, "lib/betterdocs/result_representer.rb".freeze, "lib/betterdocs/result_representer_collector.rb".freeze, "lib/betterdocs/sanitizer.rb".freeze, "lib/betterdocs/section.rb".freeze, "lib/betterdocs/version.rb".freeze]
15
+ s.files = [".codeclimate.yml".freeze, ".gitignore".freeze, ".rspec".freeze, ".semaphore/semaphore.yml".freeze, ".tool-versions".freeze, ".vscode/settings.json".freeze, "COPYING".freeze, "Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "betterdocs.gemspec".freeze, "lib/betterdocs.rb".freeze, "lib/betterdocs/controller_collector.rb".freeze, "lib/betterdocs/dsl.rb".freeze, "lib/betterdocs/dsl/common.rb".freeze, "lib/betterdocs/dsl/controller.rb".freeze, "lib/betterdocs/dsl/controller/action.rb".freeze, "lib/betterdocs/dsl/controller/action/param.rb".freeze, "lib/betterdocs/dsl/controller/action/response.rb".freeze, "lib/betterdocs/dsl/controller/controller.rb".freeze, "lib/betterdocs/dsl/controller/controller_base.rb".freeze, "lib/betterdocs/dsl/json_params.rb".freeze, "lib/betterdocs/dsl/json_params/param.rb".freeze, "lib/betterdocs/dsl/json_type_mapper.rb".freeze, "lib/betterdocs/dsl/naming.rb".freeze, "lib/betterdocs/dsl/representer.rb".freeze, "lib/betterdocs/dsl/result.rb".freeze, "lib/betterdocs/dsl/result/collection_property.rb".freeze, "lib/betterdocs/dsl/result/link.rb".freeze, "lib/betterdocs/dsl/result/property.rb".freeze, "lib/betterdocs/generator/config_shortcuts.rb".freeze, "lib/betterdocs/generator/markdown.rb".freeze, "lib/betterdocs/generator/markdown/templates/README.md.erb".freeze, "lib/betterdocs/generator/markdown/templates/section.md.erb".freeze, "lib/betterdocs/generator/swagger.rb".freeze, "lib/betterdocs/generator/swagger_static/index.html".freeze, "lib/betterdocs/global.rb".freeze, "lib/betterdocs/json_params_representer.rb".freeze, "lib/betterdocs/json_params_representer_collector.rb".freeze, "lib/betterdocs/json_time_with_zone.rb".freeze, "lib/betterdocs/mix_into_controller.rb".freeze, "lib/betterdocs/railtie.rb".freeze, "lib/betterdocs/rake_tasks.rb".freeze, "lib/betterdocs/representer.rb".freeze, "lib/betterdocs/responding.rb".freeze, "lib/betterdocs/result_representer.rb".freeze, "lib/betterdocs/result_representer_collector.rb".freeze, "lib/betterdocs/sanitizer.rb".freeze, "lib/betterdocs/section.rb".freeze, "lib/betterdocs/tasks/doc.rake".freeze, "lib/betterdocs/version.rb".freeze, "spec/assets/app/assets/images/logos/logo.png".freeze, "spec/assets/app/controllers/api/foos_controller.rb".freeze, "spec/assets/app/views/api_v4/documentation/assets/CHANGELOG.md".freeze, "spec/assets/config/betterdocs.yml".freeze, "spec/betterdocs/dsl/controller/action/param_spec.rb".freeze, "spec/betterdocs/dsl/controller/action/response_spec.rb".freeze, "spec/betterdocs/dsl/json_type_mapper_spec.rb".freeze, "spec/betterdocs/dsl/result/collection_property_spec.rb".freeze, "spec/betterdocs/dsl/result/link_spec.rb".freeze, "spec/betterdocs/dsl/result/property_spec.rb".freeze, "spec/betterdocs/generator/markdown_spec.rb".freeze, "spec/betterdocs/global_spec.rb".freeze, "spec/betterdocs/json_params_representer_spec.rb".freeze, "spec/betterdocs/result_representer_spec.rb".freeze, "spec/betterdocs/sanitizer_spec.rb".freeze, "spec/controller_dsl_spec.rb".freeze, "spec/result_representer_dsl_spec.rb".freeze, "spec/spec_helper.rb".freeze]
16
16
  s.homepage = "https://github.com/betterplace/betterdocs".freeze
17
17
  s.rdoc_options = ["--title".freeze, "Betterdocs".freeze, "--main".freeze, "README.md".freeze]
18
18
  s.rubygems_version = "3.3.26".freeze
@@ -17,8 +17,13 @@ class Betterdocs::Dsl::Controller::Action::Response
17
17
 
18
18
  def data
19
19
  @data ||= instance_eval(&@data_block)
20
- if hash = @data.ask_and_send(:to_hash)
21
- hash[:data].present? or raise Error, "result for #{controller}##{action} is empty"
20
+ @data.is_a? Betterdocs::Responding or
21
+ raise Error, "result #{@data.class} is not Betterdocs::Responding"
22
+ hash = @data.to_hash
23
+ if hash.key?(:data) && hash[:data].empty?
24
+ raise Error, "result data for action #{controller}##{action} is empty"
25
+ elsif hash.empty?
26
+ raise Error, "result for action #{controller}##{action} is empty"
22
27
  end
23
28
  @data
24
29
  rescue => e
@@ -48,7 +53,12 @@ class Betterdocs::Dsl::Controller::Action::Response
48
53
  end
49
54
 
50
55
  def to_json(*a)
56
+ data.nil? and raise Error, "result for action #{controller}##{action} was nil"
57
+ unless data.is_a?(Betterdocs::Responding)
58
+ infobar.puts "#{data.class}".red
59
+ infobar.puts "Result of type #{data.class} for action #{controller}##{action} is not hash / Betterdocs::Representer"
60
+ end
51
61
  my_data = data.ask_and_send(:to_hash) || data
52
- my_data.to_json(*a)
62
+ data.to_json(*a)
53
63
  end
54
64
  end
@@ -1,4 +1,5 @@
1
1
  require 'action_controller'
2
+ require 'betterdocs/responding'
2
3
 
3
4
  module Betterdocs::Representer
4
5
  extend ActiveSupport::Concern
@@ -9,6 +10,8 @@ module Betterdocs::Representer
9
10
  end.hashify(self)
10
11
  end
11
12
 
13
+ alias to_hash as_json
14
+
12
15
  def to_json(*a)
13
16
  JSON::generate(as_json, *a)
14
17
  end
@@ -0,0 +1,7 @@
1
+ # This module should be included in all objects used in an API response which
2
+ # should implement a #to_hash method.
3
+ module Betterdocs
4
+ module Responding
5
+ implement :to_hash, :submodule
6
+ end
7
+ end
@@ -5,6 +5,7 @@ module Betterdocs::ResultRepresenter
5
5
  extend ActiveSupport::Concern
6
6
  include Betterdocs::Dsl::Common
7
7
  include Betterdocs::Representer
8
+ include Betterdocs::Responding
8
9
 
9
10
  module ClassMethods
10
11
  def hashify(object)
@@ -1,6 +1,6 @@
1
1
  module Betterdocs
2
2
  # Betterdocs version
3
- VERSION = '0.11.0'
3
+ VERSION = '0.12.1'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/lib/betterdocs.rb CHANGED
@@ -14,8 +14,10 @@ module Betterdocs
14
14
  end
15
15
 
16
16
  require 'betterdocs/version'
17
+ require 'betterdocs/responding'
17
18
  require 'betterdocs/dsl'
18
19
  require 'betterdocs/sanitizer'
20
+ require 'betterdocs/representer'
19
21
  require 'betterdocs/result_representer'
20
22
  require 'betterdocs/result_representer_collector'
21
23
  require 'betterdocs/controller_collector'
@@ -18,7 +18,7 @@ describe Betterdocs::Dsl::Controller::Action::Response do
18
18
  'Result',
19
19
  representer: representer,
20
20
  to_hash: { data: %w[ fake-it ] }
21
- )
21
+ ).extend Betterdocs::Responding
22
22
  end
23
23
 
24
24
  let :response do
@@ -41,10 +41,23 @@ describe Betterdocs::Dsl::Controller::Action::Response do
41
41
  end
42
42
 
43
43
  it 'complains about missing data in example responses' do
44
- allow(result_data).to receive(:to_hash).and_return('data' => [])
44
+ allow(result_data).to receive(:to_hash).and_return(data: [])
45
45
  expect { response.data }.to raise_error(Betterdocs::Dsl::Controller::Action::Response::Error)
46
46
  end
47
47
 
48
+ context 'foo' do
49
+ let :result_data do
50
+ double
51
+ end
52
+
53
+ it "complains about data that isn't Betterdocs::Responding" do
54
+ expect { response.data }.to raise_error(
55
+ Betterdocs::Dsl::Controller::Action::Response::Error,
56
+ /is not Betterdocs::Responding/
57
+ )
58
+ end
59
+ end
60
+
48
61
  it 'has data' do
49
62
  expect(response.data).to eq result_data
50
63
  end
@@ -71,9 +71,4 @@ describe Betterdocs::JsonParamsRepresenter do
71
71
  expect(param.required).to eq true
72
72
  end
73
73
  end
74
-
75
- it 'foos' do
76
- puts docs.to_s
77
- skip
78
- end
79
74
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: betterdocs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - betterplace Developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-07 00:00:00.000000000 Z
11
+ date: 2022-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -199,6 +199,7 @@ extra_rdoc_files:
199
199
  - lib/betterdocs/railtie.rb
200
200
  - lib/betterdocs/rake_tasks.rb
201
201
  - lib/betterdocs/representer.rb
202
+ - lib/betterdocs/responding.rb
202
203
  - lib/betterdocs/result_representer.rb
203
204
  - lib/betterdocs/result_representer_collector.rb
204
205
  - lib/betterdocs/sanitizer.rb
@@ -251,6 +252,7 @@ files:
251
252
  - lib/betterdocs/railtie.rb
252
253
  - lib/betterdocs/rake_tasks.rb
253
254
  - lib/betterdocs/representer.rb
255
+ - lib/betterdocs/responding.rb
254
256
  - lib/betterdocs/result_representer.rb
255
257
  - lib/betterdocs/result_representer_collector.rb
256
258
  - lib/betterdocs/sanitizer.rb