Class: Rory::Application
- Inherits:
-
Object
show all
- Defined in:
- lib/rory/application.rb
Overview
Main application superclass. Applications should subclass this class, but currently no additional configuration is needed - just run ‘#spin_up’ to connect the database so Sequel can do its magic.
Defined Under Namespace
Classes: RootNotConfigured
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
.root ⇒ Object
Returns the value of attribute root.
18
19
20
|
# File 'lib/rory/application.rb', line 18
def root
@root
end
|
Instance Attribute Details
#config_path ⇒ Object
Returns the value of attribute config_path.
14
15
16
|
# File 'lib/rory/application.rb', line 14
def config_path
@config_path
end
|
#db ⇒ Object
Returns the value of attribute db.
13
14
15
|
# File 'lib/rory/application.rb', line 13
def db
@db
end
|
#db_config ⇒ Object
Returns the value of attribute db_config.
13
14
15
|
# File 'lib/rory/application.rb', line 13
def db_config
@db_config
end
|
Class Method Details
.inherited(base) ⇒ Object
20
21
22
23
|
# File 'lib/rory/application.rb', line 20
def inherited(base)
super
Rory.application = base.instance
end
|
.instance ⇒ Object
34
35
36
|
# File 'lib/rory/application.rb', line 34
def instance
@instance ||= new
end
|
.method_missing(*args, &block) ⇒ Object
25
26
27
|
# File 'lib/rory/application.rb', line 25
def method_missing(*args, &block)
instance.send(*args, &block)
end
|
.respond_to?(method) ⇒ Boolean
29
30
31
32
|
# File 'lib/rory/application.rb', line 29
def respond_to?(method)
return true if instance.respond_to?(method)
super
end
|
Instance Method Details
#auto_require_paths ⇒ Object
43
44
45
|
# File 'lib/rory/application.rb', line 43
def auto_require_paths
@auto_require_paths ||= %w(models controllers helpers)
end
|
#call(env) ⇒ Object
119
120
121
|
# File 'lib/rory/application.rb', line 119
def call(env)
stack.call(env)
end
|
78
79
80
|
# File 'lib/rory/application.rb', line 78
def configure
yield self
end
|
#connect_db(environment = ENV['RORY_ENV']) ⇒ Object
92
93
94
95
96
|
# File 'lib/rory/application.rb', line 92
def connect_db(environment = ENV['RORY_ENV'])
@db_config = load_config_data(:database)
@db = Sequel.connect(@db_config[environment.to_s])
@db.loggers << logger
end
|
#load_config_data(config_type) ⇒ Object
86
87
88
89
90
|
# File 'lib/rory/application.rb', line 86
def load_config_data(config_type)
YAML.load_file(
File.expand_path(File.join(config_path, "#{config_type}.yml"))
)
end
|
#logger ⇒ Object
123
124
125
126
127
128
129
|
# File 'lib/rory/application.rb', line 123
def logger
@logger ||= begin
Dir.mkdir('log') unless File.exists?('log')
file = File.open(File.join('log', "#{ENV['RORY_ENV']}.log"), 'a')
Logger.new(file)
end
end
|
#middleware ⇒ Object
102
103
104
|
# File 'lib/rory/application.rb', line 102
def middleware
@middleware ||= []
end
|
#require_all_files ⇒ Object
#root ⇒ Object
53
54
55
|
# File 'lib/rory/application.rb', line 53
def root
self.class.root
end
|
#root_path ⇒ Object
57
58
59
|
# File 'lib/rory/application.rb', line 57
def root_path
root || raise(RootNotConfigured, "#{self.class.name} has no root configured")
end
|
#routes ⇒ Object
71
72
73
74
75
76
|
# File 'lib/rory/application.rb', line 71
def routes
unless @routes
load(File.join(config_path, 'routes.rb'))
end
@routes
end
|
#set_routes(&block) ⇒ Object
67
68
69
|
# File 'lib/rory/application.rb', line 67
def set_routes(&block)
@routes = RouteMapper.set_routes(&block)
end
|
#spin_up ⇒ Object
82
83
84
|
# File 'lib/rory/application.rb', line 82
def spin_up
connect_db
end
|
#stack ⇒ Object
110
111
112
113
114
115
116
117
|
# File 'lib/rory/application.rb', line 110
def stack
builder = Rack::Builder.new
middleware.each do |args, block|
builder.use *args, &block
end
builder.run dispatcher
builder
end
|
#use_middleware(*args, &block) ⇒ Object
98
99
100
|
# File 'lib/rory/application.rb', line 98
def use_middleware(*args, &block)
middleware << [args, block]
end
|