GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Fork of wycats/merb-core
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/auser/merb-core.git
wycats (author)
Mon Jan 21 12:30:05 -0800 2008
commit  3de67f9f7040ea224d7007b918f15e0a1f6a2bad
tree    42d846f4d2eeb3e9e846e5d37f24b5a104b11c28
parent  15e92cc88c9797ee5f7d5b482850080ae803c1fd
merb-core / lib / merb-core.rb
100644 106 lines (89 sloc) 3.32 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
97
98
99
100
101
102
103
104
105
106
#---
# require 'merb' must happen after Merb::Config is instantiated
 
require 'rubygems'
require 'set'
require 'fileutils'
require 'socket'
 
$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'
require 'merb-core/controller/mime'
require 'merb-core/vendor/facets/inflect'
 
module Merb
  class << self
    
    def start(argv=ARGV)
      Merb::Config.parse_args(argv)
 
      if Merb::Config[:init_file]
        require(Merb.root / Merb::Config[:init_file])
      elsif File.exists?(Merb.dir_for(:config) / "merb_init")
        require(Merb.dir_for(:config) / "merb_init")
      elsif File.file?(Merb.dir_for(:application))
        require(Merb.dir_for(:application))
      end
      
      BootLoader.run
      case Merb::Config[:adapter]
      when "mongrel"
        adapter = Merb::Rack::Mongrel
      when "emongrel"
        require 'merb-core/rack/adapter/evented_mongrel'
        adapter = Merb::Rack::Mongrel
      when "webrick"
        adapter = Merb::Rack::WEBrickengl
      when "fastcgi","fcgi"
        adapter = Merb::Rack::FastCGI
      when "thin"
        adapter = Merb::Rack::Thin
      when "irb"
        adapter = Merb::Rack::Irb
      else
        adapter = Merb::Rack.const_get(Merb::Config[:adapter].capitalize)
      end
      adapter.start_server(Merb::Config[:host], Merb::Config[:port].to_i)
    end
    
    attr_accessor :environment, :load_paths
    Merb.load_paths = Hash.new { [Merb.root] } unless Merb.load_paths.is_a?(Hash)
          
    # 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
    
    def dir_for(type) Merb.load_paths[type].first end
    def glob_for(type) Merb.load_paths[type][1] 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