Module: Sinatra::Helpers::Wanted

Defined in:
lib/sinatra/helpers/wanted.rb,
lib/sinatra/helpers/wanted/version.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

Classes: WantedError, WantedMissing, WantedNotFound, WantedSyntaxError

Constant Summary collapse

VERSION =

Version

0.8
NO_VALUE =

Define a “No Value” object. It is used to signal that a parameter exists but as no associated value.

Object.new.then {|o|
    def o.insect
        "No_Value"
    end
}.freeze

Instance Method Summary collapse

Instance Method Details

#want(param, type = nil, getter = nil, id: nil, default: nil, no_value: NO_VALUE, missing: :ignore, not_found: :ignore) {|obj| ... } ⇒ Object, ...

Retrieve value/object associated with a parameter.

Parameters:

  • param (Symbol, Object, nil, NO_VALUE)

    parameter key or parameter value

  • type (#[], #call) (defaults to: nil)

    type checking / coercion

  • getter (#[], #get, #fetch, #call, #new) (defaults to: nil)

    object getter

  • id (Symbol) (defaults to: nil)

    name of the parameter being processed

  • default (Object) (defaults to: nil)

    default value to use if parameter is missing

  • no_value (Obejct) (defaults to: NO_VALUE)

    default value to use if object is not found

  • missing (:raise, :ignore, :return) (defaults to: :ignore)

    how to deal with missing parameter

  • not_found (:false, :ignore, :not_found, :pass) (defaults to: :ignore)

    how to deal with object not found

Yield Parameters:

  • obj (Object)

    retrieve parameter value/object

Yield Returns:

  • (Object)

    modified value/object

Returns:

  • (Object)

    parameter value/object

  • (nil)

    parameter is missing or it’s value is nil

  • (NO_VALUE)

    parameter has no associated value

Raises:



59
60
61
62
63
64
65
66
67
# File 'lib/sinatra/helpers/wanted.rb', line 59

def want(param, type=nil, getter=nil, id: nil,
         default: nil, no_value: NO_VALUE,
         missing: :ignore, not_found: :ignore, &block)
    error_handler do
        _want(param, type, getter, id: id,
              default: default, no_value: no_value,
              missing: missing, not_found: not_found, &block)
    end
end

#want!(param, type = nil, getter = nil, id: nil, default: nil, no_value: NO_VALUE, missing: :raise, not_found: :raise) {|obj| ... } ⇒ Object, ...

Retrieve value/object associated with a parameter.

Parameters:

  • param (Symbol, Object, nil, NO_VALUE)

    parameter key or parameter value

  • type (#[], #call) (defaults to: nil)

    type checking / coercion

  • getter (#[], #get, #fetch, #call, #new) (defaults to: nil)

    object getter

  • id (Symbol) (defaults to: nil)

    name of the parameter being processed

  • default (Object) (defaults to: nil)

    default value to use if parameter is missing

  • no_value (Obejct) (defaults to: NO_VALUE)

    default value to use if object is not found

  • missing (:raise, :ignore, :return) (defaults to: :raise)

    how to deal with missing parameter

  • not_found (:false, :ignore, :not_found, :pass) (defaults to: :raise)

    how to deal with object not found

Yield Parameters:

  • obj (Object)

    retrieve parameter value/object

Yield Returns:

  • (Object)

    modified value/object

Returns:

  • (Object)

    parameter value/object

  • (nil)

    parameter is missing or it’s value is nil

  • (NO_VALUE)

    parameter has no associated value

Raises:



70
71
72
73
74
75
76
# File 'lib/sinatra/helpers/wanted.rb', line 70

def want!(param, type=nil, getter=nil, id: nil,
          default: nil, no_value: NO_VALUE,
          missing: :raise, not_found: :raise, &block)
    want(param, type, getter, id: id,
         default: default, no_value: no_value,
         missing: missing, not_found: not_found, &block)
end

#want?(param, type = nil, getter = nil, id: nil, default: nil, no_value: NO_VALUE, missing: :return, not_found: :ignore) {|obj| ... } ⇒ Object, ...

Retrieve value/object associated with a parameter.

Parameters:

  • param (Symbol, Object, nil, NO_VALUE)

    parameter key or parameter value

  • type (#[], #call) (defaults to: nil)

    type checking / coercion

  • getter (#[], #get, #fetch, #call, #new) (defaults to: nil)

    object getter

  • id (Symbol) (defaults to: nil)

    name of the parameter being processed

  • default (Object) (defaults to: nil)

    default value to use if parameter is missing

  • no_value (Obejct) (defaults to: NO_VALUE)

    default value to use if object is not found

  • missing (:raise, :ignore, :return) (defaults to: :return)

    how to deal with missing parameter

  • not_found (:false, :ignore, :not_found, :pass) (defaults to: :ignore)

    how to deal with object not found

Yield Parameters:

  • obj (Object)

    retrieve parameter value/object

Yield Returns:

  • (Object)

    modified value/object

Returns:

  • (Object)

    parameter value/object

  • (nil)

    parameter is missing or it’s value is nil

  • (NO_VALUE)

    parameter has no associated value

Raises:



79
80
81
82
83
84
85
# File 'lib/sinatra/helpers/wanted.rb', line 79

def want?(param, type=nil, getter=nil, id: nil,
          default: nil, no_value: NO_VALUE,
          missing: :return, not_found: :ignore, &block)
    want(param, type, getter,
         default: default, id: id, no_value: no_value,
         missing: missing, not_found: not_found, &block)
end