public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Search Repo:
commit  7dffeb416ffd4f55763551387cabf6c7aff441c4
tree    94306e7ee23b53d4a690f6c06a9823173b151c61
parent  86eef63c291eb02a236ee9f966aee55c0b0c21b0
merb-core / lib / merb.rb
100644 96 lines (82 sloc) 2.784 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#---
# require 'merb' must happen after Merb::Config is instantiated
 
require 'rubygems'
require 'set'
require 'fileutils'
require "assistance"
 
$LOAD_PATH.push File.dirname(__FILE__) unless
  $LOAD_PATH.include?(File.dirname(__FILE__)) ||
  $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
 
require 'merb_core/autoload'
require 'merb_core/core_ext'
require 'merb_core/gem_ext/erubis'
require 'merb_core/logger'
require 'merb_core/version'
 
 
module Merb
  class << self
    
    def start(argv=ARGV)
      Merb::Config.parse_args(argv)
      BootLoader.run
      case Merb::Config[:adapter]
      when nil
        # Guess.
        if ENV.include?("PHP_FCGI_CHILDREN")
          adapter = Merb::Rack::FastCGI
        else
          begin
            adapter = Merb::Rack::Mongrel
          rescue LoadError => e
            adapter = Merb::Rack::WEBrick
          end
        end
      when "mongrel"
        adapter = Merb::Rack::Mongrel
      when "webrick"
        adapter = Merb::Rack::WEBrick
      when "fastcgi"
        adapter = Merb::Rack::FastCGI
      else
        adapter = Merb::Rack.const_get(server.capitalize)
      end
      adapter.start_server(Merb::Config[:host], Merb::Config[:port])
    end
    
    attr_accessor :environment, :load_paths
    Merb.load_paths = Hash.new
    
    # This is the core mechanism for setting up your application layout
    # merb-core won't set a default application layout, but merb-more will
    # use the app/:type layout that is in use in Merb 0.5
    #
    # ==== Parameters
    # type<Symbol>:: The type of path being registered (i.e. :view)
    # path<String>:: The full path
    # file_glob<String>::
    # A glob that will be used to autoload files under the path
    def push_path(type, path, file_glob = "**/*.rb") enforce!(type => Symbol)
     load_paths[type] = [path, file_glob]
    end
    
    # Application paths
    def root() @root || Merb::Config[:merb_root] || Dir.pwd end
    # ==== Parameters
    # value<String>:: the path to the root of the directory
    def root=(value) @root = value end
    # ==== Parameters
    # path<String>:: the path to a directory under the root
    def root_path(path) File.join(root, path) end
    
    # Logger settings
    attr_accessor :logger
    
    def log_path
     if $TESTING
        "#{Merb.root}/log/merb_test.log"
      elsif !(Merb::Config[:daemonize] || Merb::Config[:cluster] )
        STDOUT
      else
        "#{Merb.root}/log/merb.#{Merb::Config[:port]}.log"
     end
    end
    
    # Framework paths
    def framework_root() @framework_root ||= File.dirname(__FILE__) end
    
    # Set up default generator scope
    attr_accessor :generator_scope
    Merb.generator_scope = [:merb_default, :merb, :rspec]
  end
 
end