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
- .application ⇒ Object
-
.config {|_self| ... } ⇒ Object
Default way to setup Petit Petit.config do |config| config.link_source = “routes.yml” end.
- .link_source ⇒ Object
-
.links(source = self.link_source) ⇒ Object
Loads the YAML file with link and returns a hash with urls.
- .server ⇒ Object
Class Method Details
.application ⇒ Object
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
55 56 57 |
# File 'lib/petit.rb', line 55 def config yield self end |
.link_source ⇒ Object
20 21 22 |
# File 'lib/petit.rb', line 20 def link_source @@link_source ||= "links.yml" end |
.links(source = self.link_source) ⇒ Object
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 |