Module: Petit

Defined in:
lib/petit.rb,
lib/petit/router.rb,
lib/petit/rack_helper.rb

Defined Under Namespace

Modules: RackHelper Classes: Router

Class Method Summary collapse

Class Method Details

.applicationObject



60
61
62
# File 'lib/petit.rb', line 60

def application
  Router.application
end

.config {|_self| ... } ⇒ Object

Default way to setup Petit Petit.config do |config|

config.link_source = "routes.yml"

end

Yields:

  • (_self)

Yield Parameters:

  • _self (Petit)

    the object that the method was called on



55
56
57
# File 'lib/petit.rb', line 55

def config
  yield self
end


20
21
22
# File 'lib/petit.rb', line 20

def link_source
  @@link_source ||= "links.yml"
end

Loads the YAML file with link and returns a hash with urls

source - source of the links file

Example:

# contents of links.yml
# :root http://my_app_with_long_domain.com
# :foo  http://bar.com

Petit.links("links.yml)
# will return:
# {
# '/' => 'http://my_app_with_long_domain.com',
# '/foo' => 'http://bar.com'
# }


39
40
41
42
43
44
45
46
47
48
49
# File 'lib/petit.rb', line 39

def links(source = self.link_source)
  unless @links
    @links = {}
    links = YAML::load(File.open(link_source))
    links.each do |key,url|
      @links["/#{key}"] = url
    end
    @links.rename_key("/root","/")
  end
  @links
end

.serverObject



65
66
67
# File 'lib/petit.rb', line 65

def server
  Router.server
end