dox 0.0.3 → 1.0.0.alpha

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: e3017b4de18be018219c96ccc514f70cca773b8a
4
- data.tar.gz: 9fd458348cb00703b8e4a0beb7ab5a962c0c50c7
3
+ metadata.gz: 9535d1b95849fc4c0dddff91c5ed6a35879d6505
4
+ data.tar.gz: c84f5af01e5de1524b533175a6141d67b995bee3
5
5
  SHA512:
6
- metadata.gz: 60c5c361bcdaae16d47f468f524076f832ecf5fd86160378833e2700513d951e65fcaa11fb401af7bdbe1878e1b4b9164153b074c806e431a3cdbab298e783e4
7
- data.tar.gz: b0b2c7871768c293b2ff487cc7f1e1fbc10df6b59009da3d0da5a8cf5509de97aca332ba8f78cc6f1aa621c34da8a658933717311a15a7e6d18f2c983f45000a
6
+ metadata.gz: a7ee68d768d9fbbf34708e1cbb901fee9dd532d09807cbd9ffa0abb60d08d80c08114014280390f8532788b68e517d29dc70ebdb6ab678057e0dbfc51566ad3d
7
+ data.tar.gz: 900ec7205240057d71ae6f8c1753aabe9d03d66375dbf167336b7444f2d5840969b1ed510cf25011963807c382c051976a7fb6189178ebe1335ed96370fab653
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
+ --require spec_helper
data/README.md CHANGED
@@ -94,7 +94,7 @@ Descriptions folder is a fullpath of a folder that contains markdown files with
94
94
 
95
95
  ``` ruby
96
96
  Dox.configure do |config|
97
- config.root_api_file = 'api.md'
97
+ config.header_file_path = 'api.md'
98
98
  config.desc_folder_path = Rails.root.join('spec/support/api_doc/v1/markdown_descriptions')
99
99
  end
100
100
  ```
@@ -29,4 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "bundler", "~> 1.11"
30
30
  spec.add_development_dependency "rake", "~> 10.0"
31
31
  spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency "pry"
33
+ spec.add_runtime_dependency "rspec-core"
34
+ spec.add_runtime_dependency "rails", ">= 4.0"
32
35
  end
data/lib/dox.rb CHANGED
@@ -1,23 +1,27 @@
1
- require "rspec/rails"
2
- require "dox/version"
3
- require "dox/config"
4
- require "dox/formatter"
5
- require "dox/dsl/attr_proxy"
6
- require "dox/dsl/action"
7
- require "dox/dsl/resource"
8
- require "dox/dsl/resource_group"
9
- require "dox/dsl/documentation"
10
- require "dox/dsl/syntax"
11
- require "dox/entities/action"
12
- require "dox/entities/example"
13
- require "dox/entities/resource"
14
- require "dox/entities/resource_group"
15
- require "dox/printers/base_printer"
16
- require "dox/printers/action_printer"
17
- require "dox/printers/document_printer"
18
- require "dox/printers/example_printer"
19
- require "dox/printers/resource_group_printer"
20
- require "dox/printers/resource_printer"
1
+ require 'dox/config'
2
+ require 'dox/dsl/attr_proxy'
3
+ require 'dox/dsl/action'
4
+ require 'dox/dsl/documentation'
5
+ require 'dox/dsl/resource_group'
6
+ require 'dox/dsl/resource'
7
+ require 'dox/dsl/syntax'
8
+ require 'dox/entities/action'
9
+ require 'dox/entities/example'
10
+ require 'dox/entities/resource_group'
11
+ require 'dox/entities/resource'
12
+ require 'dox/errors/file_not_found_error'
13
+ require 'dox/errors/folder_not_found_error'
14
+ require 'dox/errors/invalid_action_error'
15
+ require 'dox/errors/invalid_resource_error'
16
+ require 'dox/errors/invalid_resource_group_error'
17
+ require 'dox/formatter'
18
+ require 'dox/printers/base_printer'
19
+ require 'dox/printers/action_printer'
20
+ require 'dox/printers/document_printer'
21
+ require 'dox/printers/example_printer'
22
+ require 'dox/printers/resource_group_printer'
23
+ require 'dox/printers/resource_printer'
24
+ require 'dox/version'
21
25
 
22
26
 
23
27
  module Dox
@@ -1,11 +1,16 @@
1
1
  module Dox
2
2
  class Config
3
3
 
4
- attr_accessor :root_api_file, :desc_folder_path
4
+ attr_reader :header_file_path, :desc_folder_path
5
5
 
6
- def initialize
7
- @root_api_file = 'api.md'
8
- @desc_folder_path = Rails.root.join('')
6
+ def header_file_path=(file_path)
7
+ raise(Errors::FileNotFoundError, file_path) unless File.exists?(file_path)
8
+ @header_file_path = file_path
9
+ end
10
+
11
+ def desc_folder_path=(folder_path)
12
+ raise(Errors::FolderNotFoundError, folder_path) unless Dir.exists?(folder_path)
13
+ @desc_folder_path = folder_path
9
14
  end
10
15
 
11
16
  end
@@ -9,26 +9,21 @@ module Dox
9
9
  attr_writer :desc
10
10
  attr_writer :params
11
11
 
12
- def initialize(opts = {})
13
- self.name = opts.fetch(:name, nil)
14
- self.verb = opts.fetch(:verb, nil)
15
- self.path = opts.fetch(:path, nil)
16
- self.desc = opts.fetch(:desc, nil)
17
- self.params = opts.fetch(:params, nil)
18
- end
12
+ def initialize(name, &block)
13
+ self.name = name
14
+ instance_eval(&block) if block_given?
19
15
 
20
- def param(signature)
21
- params << signature
16
+ raise(Dox::Errors::InvalidActionError, 'Action name is required!') if @name.blank?
22
17
  end
23
18
 
24
19
  def config
25
- Hash.new.tap do |config|
26
- config[:action_name] = @name if @name
27
- config[:action_verb] = @verb if @verb
28
- config[:action_path] = @path if @path
29
- config[:action_desc] = @desc if @desc
30
- config[:action_params] = @params if @params
31
- end
20
+ {
21
+ action_name: @name.presence,
22
+ action_verb: @verb.presence,
23
+ action_path: @path.presence,
24
+ action_desc: @desc.presence,
25
+ action_params: @params.presence
26
+ }
32
27
  end
33
28
  end
34
29
  end
@@ -10,19 +10,16 @@ module Dox
10
10
  self.subject = opts.fetch :subject
11
11
  end
12
12
 
13
- def resource(name = nil, &block)
14
- self._resource = Resource.new(name: name)
15
- _resource.instance_eval(&block)
13
+ def resource(name, &block)
14
+ self._resource = Resource.new(name, &block)
16
15
  end
17
16
 
18
- def action(name = nil, &block)
19
- self._action = Action.new(name: name)
20
- _action.instance_eval(&block)
17
+ def action(name, &block)
18
+ self._action = Action.new(name, &block)
21
19
  end
22
20
 
23
- def group(name = nil, &block)
24
- self._group = ResourceGroup.new(name: name)
25
- _group.instance_eval(&block)
21
+ def group(name, &block)
22
+ self._group = ResourceGroup.new(name: name, &block)
26
23
  end
27
24
 
28
25
  def config
@@ -5,24 +5,28 @@ module Dox
5
5
 
6
6
  attr_writer :name
7
7
  attr_writer :group
8
- attr_writer :desc
9
8
  attr_writer :endpoint
10
9
 
11
- def initialize(opts = {})
12
- self.name = opts.fetch(:name, nil)
13
- self.desc = opts.fetch(:desc, nil)
14
- self.group = opts.fetch(:group, nil)
15
- self.endpoint = opts.fetch(:endpoint, nil)
10
+ attr_writer :desc
11
+
12
+ def initialize(name, &block)
13
+ self.name = name
14
+
15
+ instance_eval(&block)
16
+
17
+ raise(Dox::Errors::InvalidResourceError, 'Resource name is required!') if @name.blank?
18
+ raise(Dox::Errors::InvalidResourceError, 'Resource group is required!') if @group.blank?
19
+ raise(Dox::Errors::InvalidResourceError, 'Resource endpoint is required!') if @endpoint.blank?
16
20
  end
17
21
 
18
22
  def config
19
- {}.tap do |config|
20
- config[:resource_name] = @name if @name
21
- config[:resource_desc] = @desc if @desc
22
- config[:resource_group_name] = @group if @group
23
- config[:resource_endpoint] = @endpoint if @endpoint
24
- config[:apidoc] = true
25
- end
23
+ {
24
+ resource_name: @name.presence,
25
+ resource_desc: @desc.presence,
26
+ resource_group_name: @group.presence,
27
+ resource_endpoint: @endpoint.presence,
28
+ apidoc: true
29
+ }
26
30
  end
27
31
  end
28
32
  end
@@ -6,17 +6,19 @@ module Dox
6
6
  attr_writer :name
7
7
  attr_writer :desc
8
8
 
9
- def initialize(opts = {})
10
- self.name = opts.fetch(:name, nil)
11
- self.desc = opts.fetch(:desc, nil)
9
+ def initialize(name, &block)
10
+ self.name = name
11
+ instance_eval(&block) if block_given?
12
+
13
+ raise(Dox::Errors::InvalidResourceGroupError, 'Resource group name is required!') if @name.blank?
12
14
  end
13
15
 
14
16
  def config
15
- {}.tap do |config|
16
- config[:resource_group_name] = @name if @name
17
- config[:resource_group_desc] = @desc if @desc
18
- config[:apidoc] = true
19
- end
17
+ {
18
+ resource_group_name: @name.presence,
19
+ resource_group_desc: @desc.presence,
20
+ apidoc: true
21
+ }
20
22
  end
21
23
  end
22
24
  end
@@ -3,30 +3,28 @@ module Dox
3
3
  module Syntax
4
4
  extend ActiveSupport::Concern
5
5
 
6
- class_methods do
7
- def document(subject, &block)
8
- documentation = _subjects[subject] = Documentation.new(subject: subject)
9
- documentation.instance_eval(&block)
10
- end
6
+ def document(subject, &block)
7
+ documentation = _subjects[subject] = Documentation.new(subject: subject)
8
+ documentation.instance_eval(&block)
9
+ end
11
10
 
12
- def const_missing(name)
13
- documentation = _subjects[infer_subject(name)]
14
- return super unless documentation
11
+ def const_missing(name)
12
+ documentation = _subjects[infer_subject(name)]
13
+ return super unless documentation
15
14
 
16
- Module.new do
17
- define_singleton_method :included do |base|
18
- base.metadata.merge! documentation.config
19
- end
15
+ Module.new do
16
+ define_singleton_method :included do |base|
17
+ base.metadata.merge! documentation.config
20
18
  end
21
19
  end
20
+ end
22
21
 
23
- def infer_subject(name)
24
- name.to_s.underscore.to_sym
25
- end
22
+ def infer_subject(name)
23
+ name.to_s.underscore.to_sym
24
+ end
26
25
 
27
- def _subjects
28
- @_subjects ||= {}
29
- end
26
+ def _subjects
27
+ @_subjects ||= {}
30
28
  end
31
29
  end
32
30
  end
@@ -1,18 +1,32 @@
1
1
  module Dox
2
2
  module Entities
3
3
  class Action
4
+ attr_reader :name, :desc, :verb, :path, :uri_params
5
+ attr_accessor :examples
4
6
 
5
- attr_accessor :name, :desc, :verb, :path, :uri_params, :examples
6
-
7
- def initialize(name, details)
7
+ def initialize(name, details, request)
8
+ @request = request
8
9
  @name = name
9
10
  @desc = details[:action_desc]
10
- @verb = details[:action_verb]
11
- @path = details[:action_path]
11
+ @verb = details[:action_verb] || request.method
12
+ @path = details[:action_path] || template_path
12
13
  @uri_params = details[:action_params]
13
14
  @examples = []
14
15
  end
15
16
 
17
+ private
18
+
19
+ attr_reader :request
20
+
21
+ def template_path
22
+ path_params = request.path_parameters.symbolize_keys.except(:action, :controller)
23
+ path = request.path.dup
24
+ path_params.each do |key, value|
25
+ # /pokemons/1 => pokemons/{id}
26
+ path.sub!(/\/#{value}(\/|$)/, "/{#{key}}\\1")
27
+ end
28
+ path
29
+ end
16
30
  end
17
31
  end
18
32
  end
@@ -19,7 +19,7 @@ module Dox
19
19
  end
20
20
 
21
21
  def request_identifier
22
- fullpath
22
+ @desc
23
23
  end
24
24
 
25
25
  def response_status
@@ -34,15 +34,6 @@ module Dox
34
34
  response.body
35
35
  end
36
36
 
37
- private
38
-
39
- def fullpath
40
- if request.query_parameters.present?
41
- "#{request.path}?#{request.query_parameters.to_query}"
42
- else
43
- request.path
44
- end
45
- end
46
37
  end
47
38
  end
48
39
  end
@@ -2,7 +2,8 @@ module Dox
2
2
  module Entities
3
3
  class Resource
4
4
 
5
- attr_accessor :name, :desc, :endpoint, :actions
5
+ attr_reader :name, :desc, :endpoint
6
+ attr_accessor :actions
6
7
 
7
8
  def initialize(name, details)
8
9
  @name = name
@@ -0,0 +1,6 @@
1
+ module Dox
2
+ module Errors
3
+ class FileNotFoundError < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Dox
2
+ module Errors
3
+ class FolderNotFoundError < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Dox
2
+ module Errors
3
+ class InvalidActionError < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Dox
2
+ module Errors
3
+ class InvalidResourceError < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Dox
2
+ module Errors
3
+ class InvalidResourceGroupError < StandardError
4
+ end
5
+ end
6
+ end
@@ -49,7 +49,7 @@ module Dox
49
49
 
50
50
  def load_or_save_action_to_resource(resource)
51
51
  action_name = @current_example_data[:action_name]
52
- resource.actions[action_name] ||= Entities::Action.new(action_name, @current_example_data)
52
+ resource.actions[action_name] ||= Entities::Action.new(action_name, @current_example_data, request)
53
53
  end
54
54
 
55
55
  def move_example_to_passed
@@ -3,7 +3,7 @@ module Dox
3
3
  class ActionPrinter < BasePrinter
4
4
 
5
5
  def print(action)
6
- @output.puts "### #{action.name}\n\n#{print_desc(action.desc)}\n\n"
6
+ @output.puts "### #{action.name} [#{action.verb} #{action.path}]\n\n#{print_desc(action.desc)}\n\n"
7
7
 
8
8
  if action.uri_params.present?
9
9
  @output.puts("+ Parameters\n#{formatted_params(action.uri_params)}")
@@ -2,11 +2,8 @@ module Dox
2
2
  module Printers
3
3
  class BasePrinter
4
4
 
5
- attr_reader :descriptions_folder_path
6
-
7
5
  def initialize(output)
8
6
  @output = output
9
- @descriptions_folder_path = Dox.config.desc_folder_path
10
7
  end
11
8
 
12
9
  def print
@@ -15,17 +12,24 @@ module Dox
15
12
 
16
13
  private
17
14
 
18
- def print_desc(desc)
19
- return unless desc.present?
15
+ def descriptions_folder_path
16
+ Dox.config.desc_folder_path
17
+ end
18
+
19
+ def print_desc(desc, fullpath = false)
20
+ return if desc.blank?
20
21
 
21
22
  if desc.to_s =~ /.*\.md$/
22
- path = descriptions_folder_path.join(desc).to_s
23
+ if fullpath
24
+ path = desc
25
+ else
26
+ path = descriptions_folder_path.join(desc).to_s
27
+ end
23
28
  "<!-- include(#{path}) -->"
24
29
  else
25
30
  desc
26
31
  end
27
32
  end
28
-
29
33
  end
30
34
  end
31
35
  end
@@ -21,7 +21,7 @@ module Dox
21
21
  end
22
22
 
23
23
  def api_desc_path
24
- Dox.config.root_api_file
24
+ Dox.config.header_file_path
25
25
  end
26
26
 
27
27
  end
@@ -3,11 +3,7 @@ module Dox
3
3
  class ResourcePrinter < BasePrinter
4
4
 
5
5
  def print(resource)
6
- if resource.endpoint.present?
7
- @output.puts "\n## #{resource.name} [#{resource.endpoint}]\n\n#{print_desc(resource.desc)}\n"
8
- else
9
- @output.puts "## #{resource.name}"
10
- end
6
+ @output.puts "\n## #{resource.name} [#{resource.endpoint}]\n\n#{print_desc(resource.desc)}\n"
11
7
 
12
8
  resource.actions.each do |_, action|
13
9
  action_printer.print(action)
@@ -1,3 +1,3 @@
1
1
  module Dox
2
- VERSION = "0.0.3"
2
+ VERSION = "1.0.0.alpha"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Melita Kokot
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-22 00:00:00.000000000 Z
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,48 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-core
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '4.0'
55
97
  description:
56
98
  email:
57
99
  - melita.kokot@gmail.com
@@ -82,6 +124,11 @@ files:
82
124
  - lib/dox/entities/example.rb
83
125
  - lib/dox/entities/resource.rb
84
126
  - lib/dox/entities/resource_group.rb
127
+ - lib/dox/errors/file_not_found_error.rb
128
+ - lib/dox/errors/folder_not_found_error.rb
129
+ - lib/dox/errors/invalid_action_error.rb
130
+ - lib/dox/errors/invalid_resource_error.rb
131
+ - lib/dox/errors/invalid_resource_group_error.rb
85
132
  - lib/dox/formatter.rb
86
133
  - lib/dox/printers/action_printer.rb
87
134
  - lib/dox/printers/base_printer.rb
@@ -106,9 +153,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
153
  version: '0'
107
154
  required_rubygems_version: !ruby/object:Gem::Requirement
108
155
  requirements:
109
- - - ">="
156
+ - - ">"
110
157
  - !ruby/object:Gem::Version
111
- version: '0'
158
+ version: 1.3.1
112
159
  requirements: []
113
160
  rubyforge_project:
114
161
  rubygems_version: 2.5.1