communard 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/communard/configuration.rb +31 -10
- data/lib/communard/context.rb +8 -8
- data/lib/communard/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9d35465b96eb5d58be0796c018ee8621dc2d139
|
4
|
+
data.tar.gz: 262fddbd090945bd223795f180b3cde77cfb7f75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b761f87f3f14335888116e531945b8b400a0f87d586c768058ce8778b3e6ec146b515e3f6688708ec31dce614fff11147d3adc0903f4f0e6022f08c5dcf9963c
|
7
|
+
data.tar.gz: 0007179282297452070dc6a6283290a7bb0bfa2a65d94a33705326e1f30990bc931520aa235a778323062383e97f1cdb7a3407e4109ce31877812b091c5304e7
|
@@ -4,13 +4,16 @@ require "pathname"
|
|
4
4
|
module Communard
|
5
5
|
class Configuration
|
6
6
|
|
7
|
-
attr_accessor :environment, :root, :
|
7
|
+
attr_accessor :environment, :root, :dump_same_db, :loggers, :sql_log_level, :log_warn_duration
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
self.environment
|
11
|
-
self.root
|
12
|
-
self.logger
|
13
|
-
self.
|
10
|
+
self.environment = ENV["RACK_ENV"] || ENV["RUBY_ENV"] || ENV["RACK_ENV"] || "development"
|
11
|
+
self.root = Pathname(Dir.pwd)
|
12
|
+
self.logger = stdout_logger
|
13
|
+
self.log_level = :info
|
14
|
+
self.dump_same_db = false
|
15
|
+
self.sql_log_level = :debug
|
16
|
+
self.log_warn_duration = 0.5
|
14
17
|
yield self if block_given?
|
15
18
|
end
|
16
19
|
|
@@ -18,13 +21,31 @@ module Communard
|
|
18
21
|
self.dump_same_db = true
|
19
22
|
end
|
20
23
|
|
21
|
-
|
24
|
+
def logger=(logger)
|
25
|
+
self.loggers = [logger]
|
26
|
+
end
|
27
|
+
|
28
|
+
def loggers
|
29
|
+
Array(@loggers).compact
|
30
|
+
end
|
31
|
+
|
32
|
+
def log_level=(level)
|
33
|
+
real_level = ::Logger.const_get(level.to_s.upcase)
|
34
|
+
loggers.each do |logger|
|
35
|
+
logger.level = real_level
|
36
|
+
end
|
37
|
+
end
|
22
38
|
|
23
|
-
def
|
24
|
-
::Logger.new(
|
39
|
+
def stdout_logger(out = $stdout)
|
40
|
+
::Logger.new(out).tap { |l|
|
25
41
|
alternate = 0
|
26
|
-
l.formatter =
|
27
|
-
|
42
|
+
l.formatter = Proc.new { |sev, _, _, msg|
|
43
|
+
alternate = ((alternate + 1) % 2)
|
44
|
+
color = case sev
|
45
|
+
when "INFO" then 35 + alternate
|
46
|
+
when "DEBUG" then 90
|
47
|
+
else 31
|
48
|
+
end
|
28
49
|
"\e[#{color}m[#{sev}]\e[0m #{msg}\n"
|
29
50
|
}
|
30
51
|
}
|
data/lib/communard/context.rb
CHANGED
@@ -10,11 +10,11 @@ module Communard
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def connect(opts = options)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
::Sequel.connect(opts).tap do |connection|
|
14
|
+
connection.loggers = loggers
|
15
|
+
connection.sql_log_level = configuration.sql_log_level
|
16
|
+
connection.log_warn_duration = configuration.log_warn_duration
|
17
|
+
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def generate_migration(name: nil)
|
@@ -35,7 +35,7 @@ module Communard
|
|
35
35
|
run_without_database("CREATE DATABASE %{database_name}", env: env)
|
36
36
|
rescue Sequel::DatabaseError => error
|
37
37
|
if /database (.*) already exists/ === error.message
|
38
|
-
logger.info "Database #{$1} already exists, which is fine."
|
38
|
+
loggers.each { |logger| logger.info "Database #{$1} already exists, which is fine." }
|
39
39
|
else
|
40
40
|
raise
|
41
41
|
end
|
@@ -99,8 +99,8 @@ module Communard
|
|
99
99
|
configuration.root
|
100
100
|
end
|
101
101
|
|
102
|
-
def
|
103
|
-
configuration.
|
102
|
+
def loggers
|
103
|
+
configuration.loggers
|
104
104
|
end
|
105
105
|
|
106
106
|
end
|
data/lib/communard/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: communard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|