Module: Stretchy

Defined in:
lib/stretchy.rb,
lib/stretchy/api.rb,
lib/stretchy/node.rb,
lib/stretchy/utils.rb,
lib/stretchy/errors.rb,
lib/stretchy/scopes.rb,
lib/stretchy/factory.rb,
lib/stretchy/results.rb,
lib/stretchy/version.rb,
lib/stretchy/and_collector.rb

Overview

RubyDoc.info: YARD Doc Server

RubyDoc.info is the next generation Ruby doc server, replacing http://rdoc.info and http://yardoc.org/docs. This doc server uses YARD to generate project documentation on the fly, for both published RubyGems as well as GitHub projects.

The public doc server is hosted at http://www.rubydoc.info

Getting Started

This site is a public service and is community-supported. Patches and enhancements are welcome.

Requirements

  • Docker Desktop
  • Ruby 3.3+

Configuration

1. config/rubydoc.yml

This server uses typical Rails configuration, but we rely on a specific config/rubydoc.yml file to configure the application level settings. You should first copy the config/rubydoc.yml.sample file to config/rubydoc.yml and then edit the file to configure your server (although the defaults should provide a working experience).

cp config/rubydoc.yml.sample config/rubydoc.yml

2. Credentials

This Ruby on Rails application stores credentials in the config/credentials.yml.enc file, however for extra security this file is not checked into the repository. You can create your own credentials file by running:

rails credentials:edit

[!NOTE] You may need to export $VISUAL or $EDITOR to your preferred editor before running this command.

This is mosty only necessary when deploying or if using custom integrations. Since we do not use the session store, the standard Rails credentials are not used for the application.

Development

Clone the repository and run the setup script to install dependencies and create the database:

git clone git://github.com/docmeta/rubydoc.info
cd rubydoc.info
./bin/setup

You can also use ./bin/dev if you have already setup the project.

[!NOTE] Windows users must use WSL2 to run the development server.

Job Queue

You can inspect running jobs at http://localhost:3000/jobs in development. In production this URL is backed behind Basic Auth using mission_control-jobs.

Run WITHOUT_JOBS=1 ./bin/dev to disable the job queue in development. You can run ./bin/jobs to start a separate job queue process if needed.

Deploying

This server can be deployed using Docker swarm. In the case of a single node deployment, you can use the following commands to deploy the server:

./script/deploy

This will build the Docker image and deploy the server using the local configuration files.

Administration Commands

RubyDoc.info comes with a set of rails tasks that can be run to update remote gems, force documentation generate, or install Ruby stdlib documentation.

# Update remote gems
rails rubydoc:gems:update

# Install Ruby stdlib documentation for X.Y.Z
rails rubydoc:stdlib:install VERSION=X.Y.Z

# Generate documentation for a gem or github project (NAME=owner/repo VERSION=branch for github projects)
rails rubydoc:docs:generate NAME=library VERSION=X.Y.Z SOURCE=github|gem

Thanks

RubyDoc.info was created by Loren Segal (YARD) and Nick Plante (rdoc.info) and is a project of DOCMETA, LLC. Additional help was provided by our friendly developer community. Pull requests welcome!

(c) 2025 DOCMETA LLC. This code is distributed under the MIT license.

Defined Under Namespace

Modules: Errors, Factory, Scopes, Utils Classes: API, AndCollector, Node, Results

Constant Summary collapse

VERSION =
"0.8.0"

Class Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



78
79
80
81
82
83
84
# File 'lib/stretchy.rb', line 78

def method_missing(method, *args, &block)
  if client.respond_to?(method)
    client.send(method, *args, &block)
  else
    super
  end
end

Class Method Details

.clientObject



23
24
25
# File 'lib/stretchy.rb', line 23

def client
  @client ||= Elasticsearch::Client.new
end

.client=(client) ⇒ Object



27
28
29
# File 'lib/stretchy.rb', line 27

def client=(client)
  @client = client
end

.count_index(name, params = {}) ⇒ Object



56
57
58
# File 'lib/stretchy.rb', line 56

def count_index(name, params = {})
  client.count({index: name}.merge(params))['count']
end

.create_index(name, params = {}) ⇒ Object



48
49
50
# File 'lib/stretchy.rb', line 48

def create_index(name, params = {})
  client.indices.create({index: name}.merge(params)) unless index_exists? name
end

.delete_index(name) ⇒ Object



44
45
46
# File 'lib/stretchy.rb', line 44

def delete_index(name)
  client.indices.delete(index: name) if index_exists? name
end

.fake_resultsObject



74
75
76
# File 'lib/stretchy.rb', line 74

def fake_results
  Results.fake
end

.index_document(params = {}) ⇒ Object

Raises:

  • (IndexDoesNotExistError)


60
61
62
63
64
65
66
67
68
# File 'lib/stretchy.rb', line 60

def index_document(params = {})
  Utils.require_params!(:index_document, params, :index, :body)

  raise IndexDoesNotExistError.new(
    "index #{params[:index]} does not exist"
  ) unless index_exists? params[:index]

  client.index(params)
end

.index_exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/stretchy.rb', line 40

def index_exists?(name)
  client.indices.exists? index: name
end

.method_missing(method, *args, &block) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/stretchy.rb', line 78

def method_missing(method, *args, &block)
  if client.respond_to?(method)
    client.send(method, *args, &block)
  else
    super
  end
end

.query(options = {}) ⇒ Object



70
71
72
# File 'lib/stretchy.rb', line 70

def query(options = {})
  API.new(root: options)
end

.refresh_index(name, params = {}) ⇒ Object



52
53
54
# File 'lib/stretchy.rb', line 52

def refresh_index(name, params = {})
  client.indices.refresh({index: name}.merge(params)) if index_exists? name
end

.search(options = {}) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/stretchy.rb', line 31

def search(options = {})
  client.search(options)
rescue Elasticsearch::Transport::Transport::Errors::BadRequest => bre
  msg = bre.message[-150..-1]
  msg << "\n\n"
  msg << JSON.pretty_generate(options)
  raise msg
end