This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

implementing :doc in param definition

  • Loading branch information...
ryfow committed May 11, 2012
1 parent 2192458 commit 1d2f982d6ccb68d9f36600a2ff81144608c039a3
Showing with 32 additions and 11 deletions.
  1. +9 −8 README.md
  2. +10 −1 lib/params.rb
  3. +10 −0 lib/weasel_diesel.rb
  4. +1 −1 spec/test_services.rb
  5. +2 −1 spec/wd_documentation_spec.rb
View
@@ -22,7 +22,7 @@ describe_service "hello_world" do |service|
service.disable_auth # on by default
# INPUT
- service.param.string :name, :default => 'World'
+ service.param.string :name, :default => 'World', :doc => "The name of the person to greet."
# OUTPUT
service.response do |response|
@@ -35,7 +35,6 @@ describe_service "hello_world" do |service|
# DOCUMENTATION
service.documentation do |doc|
doc.overall "This service provides a simple hello world implementation example."
- doc.param :name, "The name of the person to greet."
doc.example "<code>curl -I 'http://localhost:9292/hello_world?name=Matt'</code>"
end
@@ -61,9 +60,15 @@ Or a more complex example using XML:
service.params do |p|
p.string :framework, :in => SpecOptions, :null => false, :required => true
- p.datetime :timestamp, :default => Time.now
+ p.datetime :timestamp,
+ :default => Time.now,
+ :doc => "The test framework used, could be one of the two following: #{SpecOptions.join(", ")}."
+
p.string :alpha, :in => ['a', 'b', 'c']
- p.string :version, :null => false
+ p.string :version,
+ :null => false,
+ :doc => "The version of the framework to use."
+
p.integer :num, :minvalue => 42
p.namespace :user do |user|
user.integer :id, :required => :true
@@ -94,10 +99,6 @@ Or a more complex example using XML:
This is a test service used to test the framework.
DOC
- # doc.params <name>, <definition>
- doc.params :framework, "The test framework used, could be one of the two following: #{SpecOptions.join(", ")}."
- doc.params :version, "The version of the framework to use."
-
# doc.example <markdown text>
doc.example <<-DOC
The most common way to use this service looks like that:
View
@@ -24,10 +24,10 @@ class Rule
# @option options [Symbol] :default The default value of the param.
# @option options [Symbol] :minvalue The minimum acceptable value.
# @option options [Symbol] :maxvalue The maximim acceptable value.
+ # @option options [Symbol] :doc Documentation for the param.
# @api public
attr_reader :options
-
# @param [Symbol, String] name
# The param's name
# @param [Hash] opts The rule options
@@ -36,6 +36,7 @@ class Rule
# @option opts [Symbol] :default The default value of the param.
# @option opts [Symbol] :minvalue The minimum acceptable value.
# @option opts [Symbol] :maxvalue The maximim acceptable value.
+ # @option opts [Symbol] :doc Documentation for the param.
# @api public
def initialize(name, opts = {})
@name = name
@@ -50,6 +51,14 @@ def namespace
@options[:space_name]
end
+ # The documentation of this Rule
+ #
+ # @return [NilClass, String]
+ # api public
+ def doc
+ @options[:doc]
+ end
+
# Converts the rule into a hash with its name and options.
#
# @return [Hash]
View
@@ -408,7 +408,17 @@ module Kernel
def describe_service(url, &block)
service = WeaselDiesel.new(url)
yield service
+
+ service.defined_params.list_optional.each do |rule|
+ service.doc.param(rule.name, rule.options[:doc]) if rule.options[:doc]
+ end
+
+ service.defined_params.list_required.each do |rule|
+ service.doc.param(rule.name, rule.options[:doc]) if rule.options[:doc]
+ end
+
WSList.add(service)
+
service
end
View
@@ -10,7 +10,7 @@
p.datetime :timestamp, :default => Time.now
p.string :alpha, :in => ['a', 'b', 'c']
p.string :version, :null => false
- p.integer :num, :minvalue => 42
+ p.integer :num, :minvalue => 42, :doc => "The number to test"
end
@@ -15,8 +15,9 @@
it "should have a list of params doc" do
@doc.params_doc.should be_an_instance_of(Hash)
- @doc.params_doc.keys.sort.should == [:framework, :version]
+ @doc.params_doc.keys.sort.should == [:framework, :num, :version]
@doc.params_doc[:framework].should == "The test framework used, could be one of the two following: #{WeaselDieselSpecOptions.join(", ")}."
+ @doc.params_doc[:num].should == 'The number to test'
end
it "should allow to define namespaced params doc" do

0 comments on commit 1d2f982

Please sign in to comment.