-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle_around.rb
More file actions
44 lines (36 loc) · 837 Bytes
/
Copy pathtoggle_around.rb
File metadata and controls
44 lines (36 loc) · 837 Bytes
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
class Application
attr_accessor :environment
def initialize
@environment = :development
end
def connect_to_database
puts "Connecting to #{@environment} database..."
end
def handle_request
puts "Handling #{@environment} request..."
end
def write_to_log
puts "Writing to #{@environment} log file..."
end
def in_environment(new_environment)
old_environment = @environment
@environment = new_environment
yield
rescue Exception => e
puts e.message
ensure
@environment = old_environment
puts "Reset environment to #{@environment}"
end
end
app = Application.new
app.in_environment(:production) do
app.connect_to_database
app.handle_request
app.write_to_log
end
app.in_environment(:test) do
app.connect_to_database
app.handle_request
app.write_to_log
end