Permalink
Browse files

Fix a bit of documentation style and add yard

  • Loading branch information...
1 parent 69c4d63 commit c1765dea800a5bf69f97fd9a93cc54bbb988f5c9 @txus txus committed May 21, 2012
Showing with 51 additions and 32 deletions.
  1. +2 −0 .gitignore
  2. +8 −0 .yardopts
  3. +4 −1 Gemfile
  4. +14 −1 Gemfile.lock
  5. +5 −15 Rakefile
  6. +6 −6 lib/hypermodel/resource.rb
  7. +12 −9 lib/hypermodel/serializers/mongoid.rb
View
@@ -5,3 +5,5 @@ test/dummy/db/*.sqlite3
test/dummy/log/*.log
test/dummy/tmp/
test/dummy/.sass-cache
+doc/
+.yardoc/
View
@@ -0,0 +1,8 @@
+--title "Hypermodel"
+--readme README.md
+--protected
+--private
+--plugin tomdoc
+lib
+-
+[A-Z]*.*
View
@@ -7,9 +7,12 @@ gemspec
# jquery-rails is used by the dummy application
gem "jquery-rails"
-gem "mongoid"
gem "bson_ext"
+gem 'redcarpet'
+gem 'yard', '~> 0.7.5'
+gem 'yard-tomdoc', git: 'git://github.com/rubyworks/yard-tomdoc'
+
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
View
@@ -1,3 +1,11 @@
+GIT
+ remote: git://github.com/rubyworks/yard-tomdoc
+ revision: caee83fb8b068fef81068e00dc8d1245354536f1
+ specs:
+ yard-tomdoc (0.5.0)
+ tomparse
+ yard
+
PATH
remote: .
specs:
@@ -86,17 +94,20 @@ GEM
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
+ redcarpet (2.1.1)
sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.6)
thor (0.14.6)
tilt (1.3.3)
+ tomparse (0.2.1)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.33)
+ yard (0.7.5)
PLATFORMS
ruby
@@ -105,5 +116,7 @@ DEPENDENCIES
bson_ext
hypermodel!
jquery-rails
- mongoid
+ redcarpet
sqlite3
+ yard (~> 0.7.5)
+ yard-tomdoc!
View
@@ -4,25 +4,15 @@ begin
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
-begin
- require 'rdoc/task'
-rescue LoadError
- require 'rdoc/rdoc'
- require 'rake/rdoctask'
- RDoc::Task = Rake::RDocTask
-end
-RDoc::Task.new(:rdoc) do |rdoc|
- rdoc.rdoc_dir = 'rdoc'
- rdoc.title = 'Hypermodel'
- rdoc.options << '--line-numbers'
- rdoc.rdoc_files.include('README.rdoc')
- rdoc.rdoc_files.include('lib/**/*.rb')
+require 'yard'
+YARD::Config.load_plugin('yard-tomdoc')
+YARD::Rake::YardocTask.new do |t|
+ t.files = ['lib/**/*.rb']
+ t.options = %w(-r README.md)
end
-
-
Bundler::GemHelper.install_tasks
require 'rake/testtask'
View
@@ -14,7 +14,7 @@ class Resource
# Public: Initializes a Resource.
#
- # record - A Mongoid instance of a model.
+ # record - A Mongoid instance of a model.
# controller - An ActionController instance.
#
# TODO: Detect record type (ActiveRecord, DataMapper, Mongoid, etc..) and
@@ -31,9 +31,9 @@ def to_json(*opts)
attributes.update(links).update(embedded).to_json(*opts)
end
- # Private: Constructs the _links section of the response.
+ # Internal: Constructs the _links section of the response.
#
- # Returns: A Hash of the links of the resource. It will include, at least,
+ # Returns a Hash of the links of the resource. It will include, at least,
# a link to itself.
def links
_links = { self: polymorphic_url(record) }
@@ -49,14 +49,14 @@ def links
{ _links: _links }
end
- # Private: Constructs the _embedded section of the response.
+ # Internal: Constructs the _embedded section of the response.
#
- # Returns: A Hash of the embedded resources of the resource.
+ # Returns a Hash of the embedded resources of the resource.
def embedded
{ _embedded: embedded_resources }
end
- # Private: Returns the url wrapped in a Hash in HAL format.
+ # Internal: Returns the url wrapped in a Hash in HAL format.
def polymorphic_url(record_or_hash_or_array, options = {})
{ href: @controller.polymorphic_url(record_or_hash_or_array, options = {}) }
end
@@ -1,6 +1,6 @@
module Hypermodel
module Serializers
- # Private: A Mongoid serializer that complies with the Hypermodel
+ # Internal: A Mongoid serializer that complies with the Hypermodel
# Serializer API.
#
# It is used by Hypermodel::Resource to extract the attributes and
@@ -24,8 +24,8 @@ def initialize(record)
# Public: Returns a Hash with the resources that are linked to the
# record. It will be used by Hypermodel::Resource.
#
- # An example of a linked resource could be the author of a post. Think of
- # `/authors/:author_id`
+ # An example of a linked resource could be the author of a post. Think
+ # of `/authors/:author_id`
#
# The format of the returned Hash must be the following:
#
@@ -62,12 +62,12 @@ def sub_resources
#
# An example of the returning Hash could be the following:
#
- # {"comments"=>
- # [
- # {"_id"=>"4fb941cb82b4d46162000007", "body"=>"Comment 1"},
- # {"_id"=>"4fb941cb82b4d46162000008", "body"=>"Comment 2"}
- # ]
- # }
+ # {"comments"=>
+ # [
+ # {"_id"=>"4fb941cb82b4d46162000007", "body"=>"Comment 1"},
+ # {"_id"=>"4fb941cb82b4d46162000008", "body"=>"Comment 2"}
+ # ]
+ # }
def embedded_resources
return {} if embedded_relations.empty?
@@ -80,7 +80,10 @@ def embedded_resources
end
end
+ #######
private
+ #######
+
def select_relations_by_type(type)
referenced_relations.select do |name, metadata|
metadata.relation == type

0 comments on commit c1765de

Please sign in to comment.