Skip to content

Commit

Permalink
chore(yard): parse docs inside included, intance_methods and class_me…
Browse files Browse the repository at this point in the history
…thods blocks
  • Loading branch information
marian13 committed Sep 24, 2023
1 parent 7f6a6a7 commit 590997b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .yardopts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
##
# NOTE: This config is used by `task docs:generate`.
#
# NOTE: `.yardopts` docs.
# https://rubydoc.info/gems/yard/YARD/CLI/Yardoc
#
Expand All @@ -9,5 +11,6 @@
--markup-provider commonmarker
--output-dir docs
--tag internal --hide-tag internal
--plugin convenient_service_concern
'lib/**/*.rb' -
README.md
8 changes: 7 additions & 1 deletion Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,13 @@ tasks:
#
docs:generate:
cmds:
- bundle exec yardoc
##
# NOTE: yard supports plugins as gems only.
# - https://rubydoc.info/gems/yard/file/docs/GettingStarted.md#plugin-support
#
# NOTE: `RUBYLIB` is used to extend Ruby's `$LOAD_PATH`. This way yard treats `./yard` folder as a directory with custom gems.
#
- RUBYLIB=./yard bundle exec yardoc

docs:generate:open:
cmds:
Expand Down
45 changes: 45 additions & 0 deletions yard/yard-convenient_service_concern.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require "yard"

##
# This file is used to allow parsing of yard docs inside `included`, `instance_methods` and `class_methods` blocks.
#
# It is loaded by the `RUBYLIB` ENV variable passed to `task docs:generate` in `Taskfile`.
#
# @see https://rubydoc.info/gems/yard/file/docs/GettingStarted.md#plugin-support
# @see https://github.com/digitalcuisine/yard-activesupport-concern
# @see https://github.com/digitalcuisine/yard-activesupport-concern/blob/v0.0.1/lib/yard-activesupport-concern.rb
# @see https://stackoverflow.com/a/901109/12201472
#
module YARD
module Concern
class IncludedHandler < YARD::Handlers::Ruby::Base
handles method_call(:included)

namespace_only

def process
parse_block(statement.last.last, namespace: namespace, scope: :instance)
end
end

class InstanceMethodsHandler < YARD::Handlers::Ruby::Base
handles method_call(:instance_methods)

namespace_only

def process
parse_block(statement.last.last, namespace: namespace, scope: :instance)
end
end

class ClassMethodsHandler < YARD::Handlers::Ruby::Base
handles method_call(:class_methods)

namespace_only

def process
parse_block(statement.last.last, namespace: namespace, scope: :class)
end
end
end
end

0 comments on commit 590997b

Please sign in to comment.