Skip to content

Commit bfe91d5

Browse files
committed
Start documenting with RDoc
1 parent 4e8831d commit bfe91d5

File tree

12 files changed

+72
-0
lines changed

12 files changed

+72
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ example/docs
44
example/public/docs
55
*.gem
66
*.swp
7+
/html/

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
source 'http://rubygems.org'
22

33
gemspec
4+
5+
gem 'inch'

Gemfile.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ GEM
3333
xpath (~> 2.0)
3434
childprocess (0.3.9)
3535
ffi (~> 1.0, >= 1.0.11)
36+
coderay (1.1.0)
3637
crack (0.4.1)
3738
safe_yaml (~> 0.9.0)
3839
cucumber (1.3.10)
@@ -48,7 +49,13 @@ GEM
4849
multi_json (~> 1.3)
4950
httpclient (2.3.4.1)
5051
i18n (0.6.5)
52+
inch (0.4.5)
53+
pry
54+
sparkr (>= 0.2.0)
55+
term-ansicolor
56+
yard (~> 0.8.7)
5157
json (1.8.1)
58+
method_source (0.8.2)
5259
mime-types (2.0)
5360
mini_portile (0.5.2)
5461
minitest (4.7.5)
@@ -57,6 +64,10 @@ GEM
5764
mustache (0.99.5)
5865
nokogiri (1.6.0)
5966
mini_portile (~> 0.5.0)
67+
pry (0.9.12.6)
68+
coderay (~> 1.0)
69+
method_source (~> 0.8)
70+
slop (~> 3.4)
6071
rack (1.5.2)
6172
rack-oauth2 (1.0.7)
6273
activesupport (>= 2.3)
@@ -82,15 +93,21 @@ GEM
8293
rack (~> 1.4)
8394
rack-protection (~> 1.4)
8495
tilt (~> 1.3, >= 1.3.4)
96+
slop (3.5.0)
97+
sparkr (0.4.1)
98+
term-ansicolor (1.3.0)
99+
tins (~> 1.0)
85100
thread_safe (0.1.3)
86101
atomic
87102
tilt (1.4.1)
103+
tins (1.1.0)
88104
tzinfo (0.3.38)
89105
webmock (1.16.0)
90106
addressable (>= 2.2.7)
91107
crack (>= 0.3.2)
92108
xpath (2.0.0)
93109
nokogiri (~> 1.3)
110+
yard (0.8.7.4)
94111

95112
PLATFORMS
96113
ruby
@@ -99,6 +116,7 @@ DEPENDENCIES
99116
aruba
100117
capybara
101118
fakefs
119+
inch
102120
rack-oauth2 (>= 0.14.4)
103121
rack-test (>= 0.6.2)
104122
rake

Rakefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ require "rspec/core/rake_task"
66
RSpec::Core::RakeTask.new(:spec)
77

88
task :default => [:spec, :cucumber]
9+
10+
require 'rdoc/task'
11+
Rake::RDocTask.new do |rd|
12+
rd.main = "README.md"
13+
rd.rdoc_files.include("README.md", "lib/**/*.rb")
14+
end

lib/rspec_api_documentation.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'cgi'
44
require 'json'
55

6+
# Namespace for RspecApiDocumentation
67
module RspecApiDocumentation
78
extend ActiveSupport::Autoload
89

@@ -62,6 +63,13 @@ def self.documentations
6263
@documentations ||= configuration.map { |config| ApiDocumentation.new(config) }
6364
end
6465

66+
# Configures RspecApiDocumentation
67+
#
68+
# See RspecApiDocumentation::Configuration for more information on configuring.
69+
#
70+
# RspecApiDocumentation.configure do |config|
71+
# config.docs_dir = "doc/api"
72+
# end
6573
def self.configure
6674
yield configuration if block_given?
6775
end

lib/rspec_api_documentation/client_base.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module RspecApiDocumentation
2+
# Base client class that documents all requests that go through it.
3+
#
4+
# client.get("/orders", { :page => 2 }, { "Accept" => "application/json" })
25
class ClientBase < Struct.new(:context, :options)
36
include Headers
47

lib/rspec_api_documentation/configuration.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,23 @@ def groups
1313
@groups ||= []
1414
end
1515

16+
# Defines a new sub configuration
17+
#
18+
# Automatically sets the `filter` to the group name, and the `docs_dir` to
19+
# a subfolder of the parent's `doc_dir` named the group name.
20+
#
21+
# RspecApiDocumentation.configure do |config|
22+
# config.docs_dir = "doc/api"
23+
# config.define_group(:public) do |config|
24+
# # Default values
25+
# config.docs_dir = "doc/api/public"
26+
# config.filter = :public
27+
# end
28+
# end
29+
#
30+
# Params:
31+
# +name+:: String name of the group
32+
# +block+:: Block configuration block
1633
def define_group(name, &block)
1734
subconfig = self.class.new(self)
1835
subconfig.filter = name
@@ -79,6 +96,7 @@ def settings
7996
@settings ||= {}
8097
end
8198

99+
# Yields itself and sub groups to hook into the Enumerable module
82100
def each(&block)
83101
yield self
84102
groups.map { |g| g.each &block }

lib/rspec_api_documentation/dsl.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
require "rspec_api_documentation/dsl/endpoint"
33
require "rspec_api_documentation/dsl/callback"
44

5+
# Custom describe block that sets metadata to enable the rest of RAD
6+
#
7+
# resource "Orders", :meta => :data do
8+
# # ...
9+
# end
10+
#
11+
# Params:
12+
# +args+:: Glob of RSpec's `describe` arguments
13+
# +block+:: Block to pass into describe
14+
#
515
def self.resource(*args, &block)
616
options = if args.last.is_a?(Hash) then args.pop else {} end
717
options[:api_doc_dsl] = :resource

lib/rspec_api_documentation/dsl/callback.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module RspecApiDocumentation::DSL
2+
# DSL Methods for testing server callbacks
23
module Callback
34
extend ActiveSupport::Concern
45

lib/rspec_api_documentation/dsl/endpoint.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'rack/test/utils'
44

55
module RspecApiDocumentation::DSL
6+
# DSL methods available inside the RSpec example.
67
module Endpoint
78
extend ActiveSupport::Concern
89
include Rack::Test::Utils
@@ -23,6 +24,7 @@ def example_request(description, params = {}, &block)
2324
end
2425

2526
private
27+
2628
# from rspec-core
2729
def relative_path(line)
2830
line = line.sub(File.expand_path("."), ".")

0 commit comments

Comments
 (0)