You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2010/07/09 01:48:51 UTC
svn commit: r962354 - in /incubator/deltacloud/trunk/client: Rakefile
lib/documentation.rb
Author: lutter
Date: Thu Jul 8 23:48:51 2010
New Revision: 962354
URL: http://svn.apache.org/viewvc?rev=962354&view=rev
Log:
Added Yard for easy documentation generation
Added:
incubator/deltacloud/trunk/client/lib/documentation.rb
Modified:
incubator/deltacloud/trunk/client/Rakefile
Modified: incubator/deltacloud/trunk/client/Rakefile
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/Rakefile?rev=962354&r1=962353&r2=962354&view=diff
==============================================================================
--- incubator/deltacloud/trunk/client/Rakefile (original)
+++ incubator/deltacloud/trunk/client/Rakefile Thu Jul 8 23:48:51 2010
@@ -20,6 +20,11 @@ require 'spec/rake/spectask'
load 'deltacloud-client.gemspec'
+desc "Generate documentation"
+task 'documentation' do
+ load 'lib/documentation.rb'
+end
+
Rake::GemPackageTask.new(@spec) do |pkg|
pkg.need_tar = true
end
@@ -27,9 +32,6 @@ end
desc "Run all examples"
Spec::Rake::SpecTask.new('spec') do |t|
t.spec_files = FileList['specs/**/*_spec.rb']
- t.spec_opts = [
- '--format html:spec_report.html'
- ]
end
desc "Setup Fixtures"
Added: incubator/deltacloud/trunk/client/lib/documentation.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/client/lib/documentation.rb?rev=962354&view=auto
==============================================================================
--- incubator/deltacloud/trunk/client/lib/documentation.rb (added)
+++ incubator/deltacloud/trunk/client/lib/documentation.rb Thu Jul 8 23:48:51 2010
@@ -0,0 +1,97 @@
+require 'lib/deltacloud'
+
+skip_methods = [ "id=", "uri=" ]
+
+begin
+ @dc=DeltaCloud.new('mockuser', 'mockpassword', 'http://localhost:3001/api')
+rescue
+ puts "Please make sure that Deltacloud API is running with Mock driver"
+ exit(1)
+end
+
+@dc.entry_points.keys.each do |ep|
+ @dc.send(ep)
+end
+class_list = @dc.classes
+
+def read_method_description(c, method)
+ if method =~ /es$/
+ " # Read #{c.downcase} collection from Deltacloud API"
+ else
+ case method
+ when "uri"
+ " # Return URI to API for this object"
+ when "action_urls"
+ " # Return available actions API URL"
+ when "client"
+ " # Return instance of API client"
+ else
+ " # Get #{method} attribute value from #{c.downcase}"
+ end
+ end
+end
+
+def read_parameters(c, method)
+ out = []
+ if method =~ /es$/
+ out << " # @param [String, #id] Filter by ID"
+ end
+ out.join("\n")
+end
+
+def read_return_value(c, method)
+ if method =~ /es$/
+ rt = "Array"
+ else
+ rt = "String"
+ end
+ " # @return [String] Value of #{method}"
+end
+
+out = []
+
+class_list.each do |c|
+ class_name = "#{c}".gsub(/^DeltaCloud::/, '')
+ out << "module DeltaCloud"
+ out << " class API"
+ @dc.entry_points.keys.each do |ep|
+ out << "# Return #{ep.to_s.classify} object with given id\n"
+ out << "# "
+ out << "# *#{@dc.documentation(ep.to_s).description}*"
+ out << "# @return [#{ep.to_s.classify}]"
+ out << "def #{ep.to_s.gsub(/s$/, '')}"
+ out << "end"
+ out << "# Return collection of #{ep.to_s.classify} objects"
+ out << "# "
+ out << "# *#{@dc.documentation(ep.to_s).description}*"
+ @dc.documentation(ep.to_s, 'index').params.each do |p|
+ out << p.to_comment
+ end
+ out << "# @return [Array] [#{ep.to_s.classify}]"
+ out << "def #{ep}(opts={})"
+ out << "end"
+ end
+ out << " end"
+ out << " class #{class_name}"
+ c.instance_methods(false).each do |method|
+ next if skip_methods.include?(method)
+ params = read_parameters(class_name, method)
+ retval = read_return_value(class_name, method)
+ out << read_method_description(class_name, method)
+ out << params if params
+ out << retval if retval
+ out << " def #{method}"
+ out << " # This method was generated dynamically from API"
+ out << " end\n"
+ end
+ out << " end"
+ out << "end"
+end
+
+FileUtils.rm_r('doc') rescue nil
+FileUtils.mkdir_p('doc')
+File.open('doc/deltacloud.rb', 'w') do |f|
+ f.puts(out.join("\n"))
+end
+system("yardoc -m markdown --readme README --title 'Deltacloud Client Library' 'lib/*.rb' 'doc/deltacloud.rb' --verbose")
+FileUtils.rm('doc/deltacloud.rb')