Class: YARD::Server::Commands::LibraryCommand Abstract
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Base
|
|
Instance Chain:
self,
Base
|
|
Inherits: |
YARD::Server::Commands::Base
|
Defined in: | lib/yard/server/commands/library_command.rb |
Overview
This is the base command for all commands that deal directly with libraries.
Some commands do not, but most (like DisplayObjectCommand
) do. If your
command deals with libraries directly, subclass this class instead.
See Base
for notes on how to subclass a command.
Class Method Summary
- .new(opts = {}) ⇒ LibraryCommand constructor
Base
- Inherited
.new | Creates a new command object, setting attributes named by keys in the options hash. |
Instance Attribute Summary
- #incremental ⇒ Boolean rw
- #library ⇒ LibraryVersion rw
- #options ⇒ LibraryOptions rw
- #serializer ⇒ Serializers::Base rw
- #single_library ⇒ Boolean rw
- #use_fork ⇒ Boolean rw
- #can_fork? ⇒ Boolean readonly private
Base
- Inherited
Instance Method Summary
- #call(request)
- #call_with_fork(request, &block) private
- #call_without_fork(request) private
-
#fulldoc_template
private
Hack to load a custom fulldoc template object that does not do any rendering/generation.
- #load_yardoc private
- #not_prepared private
- #restore_template_info private
- #save_default_template_info private
- #setup_library private
- #setup_yardopts private
Base
- Inherited
#call | The main method called by a router with a request object. |
#run | Subclass this method to implement a custom command. |
#add_cache_control | Add a conservative cache control policy to reduce load on requests served with "?1234567890" style timestamp query strings. |
Constructor Details
.new(opts = {}) ⇒ LibraryCommand
# File 'lib/yard/server/commands/library_command.rb', line 63
def initialize(opts = {}) super self.serializer = DocServerSerializer.new end
Instance Attribute Details
#can_fork? ⇒ Boolean
(readonly, private)
# File 'lib/yard/server/commands/library_command.rb', line 109
def can_fork? CAN_FORK && use_fork end
#incremental ⇒ Boolean
(rw)
# File 'lib/yard/server/commands/library_command.rb', line 53
attr_accessor :incremental
#library ⇒ LibraryVersion (rw)
# File 'lib/yard/server/commands/library_command.rb', line 41
attr_accessor :library
#options ⇒ LibraryOptions (rw)
# File 'lib/yard/server/commands/library_command.rb', line 44
attr_accessor :
#serializer ⇒ Serializers::Base (rw)
# File 'lib/yard/server/commands/library_command.rb', line 47
attr_accessor :serializer
#single_library ⇒ Boolean
(rw)
# File 'lib/yard/server/commands/library_command.rb', line 50
attr_accessor :single_library
#use_fork ⇒ Boolean
(rw)
# File 'lib/yard/server/commands/library_command.rb', line 57
attr_accessor :use_fork
Instance Method Details
#call(request)
# File 'lib/yard/server/commands/library_command.rb', line 68
def call(request) if can_fork? call_with_fork(request) { super } else begin save_default_template_info call_without_fork(request) { super } ensure restore_template_info end end end
#call_with_fork(request, &block) (private)
# File 'lib/yard/server/commands/library_command.rb', line 96
def call_with_fork(request, &block) IO.pipe(:binmode => true) do |reader, writer| fork do log.debug "[pid=#{Process.pid}] fork serving: #{request.path}" reader.close writer.print(Marshal.dump(call_without_fork(request, &block))) end writer.close Marshal.load(reader.read) end end
#call_without_fork(request) (private)
# File 'lib/yard/server/commands/library_command.rb', line 83
def call_without_fork(request) self.request = request self. = LibraryOptions.new .reset_defaults .command = self setup_library .title = "Documentation for #{library.name} " + (library.version ? '(' + library.version + ')' : '') yield rescue LibraryNotPreparedError not_prepared end
#fulldoc_template (private)
Hack to load a custom fulldoc template object that does not do any rendering/generation. We need this to access the generate_*_list methods.
# File 'lib/yard/server/commands/library_command.rb', line 171
def fulldoc_template tplopts = [ .template, :fulldoc, .format] tplclass = Templates::Engine.template(*tplopts) obj = Object.new.extend(tplclass) class << obj; define_method(:init) {} end obj.class = tplclass obj.send(:initialize, ) class << obj attr_reader :contents define_method(:asset) {|_, contents| @contents = contents } end obj end
#load_yardoc (private)
# File 'lib/yard/server/commands/library_command.rb', line 147
def load_yardoc raise LibraryNotPreparedError unless library.ready? if Thread.current[:__yard_last_yardoc__] == library.yardoc_file log.debug "Reusing yardoc file: #{library.yardoc_file}" return end Registry.clear Templates::ErbCache.clear! Registry.load_yardoc(library.yardoc_file) Thread.current[:__yard_last_yardoc__] = library.yardoc_file end
#not_prepared (private)
# File 'lib/yard/server/commands/library_command.rb', line 159
def not_prepared .update(:template => :doc_server, :type => :processing) self.caching = false self.status = 202 self.body = render self.headers = {'Content-Type' => 'text/html'} [status, headers, [body]] end
#restore_template_info (private)
# File 'lib/yard/server/commands/library_command.rb', line 118
def restore_template_info Templates::Engine.template_paths = @old_template_paths Templates::Template.extra_includes = @old_extra_includes end
#save_default_template_info (private)
# File 'lib/yard/server/commands/library_command.rb', line 113
def save_default_template_info @old_template_paths = Templates::Engine.template_paths.dup @old_extra_includes = Templates::Template.extra_includes.dup end
#setup_library (private)
# File 'lib/yard/server/commands/library_command.rb', line 123
def setup_library library.prepare! if request.xhr? && request.query['process'] load_yardoc setup_yardopts true end
#setup_yardopts (private)
# File 'lib/yard/server/commands/library_command.rb', line 130
def setup_yardopts @@library_chdir_lock.synchronize do Dir.chdir(library.source_path) do yardoc = CLI::Yardoc.new if incremental yardoc.run('-c', '-n', '--no-stats') else yardoc.parse_arguments end yardoc.send(: ) yardoc. .delete(:serializer) yardoc. .delete(:serialize) .update(yardoc. .to_hash) end end end