Module: Sinatra::AmpExtension

Defined in:
lib/amp/server/extension/amp_extension.rb

Overview

AmpExtension

This module adds a single DSL method to the sinatra base class: amp_repository. This method allows you to specify an HTTP path for an amp repo. You can call this method multiple times to specify multiple repositories for your server.

Examples:

  • This will start a server, serving the directory the file is in,

at http://localhost:4567/
   require 'amp'
   require 'sinatra'
   require 'amp/server/extension/amp_extension'

   amp_repository "/", Amp::Repositories.pick(nil, ".")

Constant Summary collapse

ACCEPTABLE_COMMANDS =

All the commands we are capable of accepting

[ 'branches', 'heads', 'lookup', 'capabilities', 'between', 'changegroup', 'changegroupsubset', 'unbundle' ]
READABLE_COMMANDS =
[ 'branches', 'heads', 'lookup', 'capabilities', 'between', 'changegroup', 'changegroupsubset' ]

Instance Method Summary collapse

Instance Method Details

#amp_repositoriesObject



27
# File 'lib/amp/server/extension/amp_extension.rb', line 27

def amp_repositories; @@amp_repositories ||= {}; end

#amp_repository(http_path, repo) ⇒ Object

This method will specify that the sinatra application should serve the repository repo using Mercurial’s HTTP(S) protocol at http_path. You can call this method multiple times for multiple repositories on different paths.

Examples:

  • This will start a server, serving the directory the file is in,

at http://localhost:4567/
   require 'amp'
   require 'sinatra'
   require 'amp/server/extension/amp_extension'

   amp_repository "/", Amp::Repositories.pick(nil, ".")

Parameters:

  • http_path (String)

    the URL path from which to serve the repository

  • repo (Repository)

    the repository being served - typically a LocalRepository.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/amp/server/extension/amp_extension.rb', line 45

def amp_repository(http_path, repo)
  amp_repositories[http_path] = repo
  
  get http_path do
    if ACCEPTABLE_COMMANDS.include?(params[:cmd])
      send("amp_get_#{params[:cmd]}".to_sym, repo)
    else
      pass
    end
  end
end