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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c9e103be14fa7120ec68d05c5dd7ec6ba00c994
4
- data.tar.gz: fb23470d09fba6b7b8fa412f82073425efcc7f80
3
+ metadata.gz: b9d35465b96eb5d58be0796c018ee8621dc2d139
4
+ data.tar.gz: 262fddbd090945bd223795f180b3cde77cfb7f75
5
5
  SHA512:
6
- metadata.gz: fc5b5ffcc913a2546606d0bd873193b33bcbf21094dd1273d31098f95851774d4937034689facd8771c1a83a92a4c88a28b834cf6480e6cf686375d7e82fae8d
7
- data.tar.gz: 243c758d06102891eee3d735112cd27b068c78c30d5b08e5a630ab52f7264c2896f99d62814cb8208d6912dd14a847808875a3eeef9daa71ce853af60857c8f1
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, :logger, :dump_same_db
7
+ attr_accessor :environment, :root, :dump_same_db, :loggers, :sql_log_level, :log_warn_duration
8
8
 
9
9
  def initialize
10
- self.environment = ENV["RACK_ENV"] || ENV["RUBY_ENV"] || ENV["RACK_ENV"] || "development"
11
- self.root = Pathname(Dir.pwd)
12
- self.logger = default_logger
13
- self.dump_same_db = false
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
- private
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 default_logger
24
- ::Logger.new($stdout).tap { |l|
39
+ def stdout_logger(out = $stdout)
40
+ ::Logger.new(out).tap { |l|
25
41
  alternate = 0
26
- l.formatter = proc { |sev, _, _, msg|
27
- color = sev == "INFO" ? 35 + ((alternate += 1) % 2) : 31
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
  }
@@ -10,11 +10,11 @@ module Communard
10
10
  end
11
11
 
12
12
  def connect(opts = options)
13
- connection = ::Sequel.connect(opts)
14
- connection.loggers = [logger]
15
- connection.sql_log_level = :debug
16
- connection.log_warn_duration = 1
17
- connection
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 logger
103
- configuration.logger
102
+ def loggers
103
+ configuration.loggers
104
104
  end
105
105
 
106
106
  end
@@ -1,3 +1,3 @@
1
1
  module Communard
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
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-12 00:00:00.000000000 Z
11
+ date: 2014-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel