buzztools 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/buzztools/extend_array.rb +0 -4
- data/lib/buzztools/extend_bignum.rb +3 -11
- data/lib/buzztools/extend_fixnum.rb +0 -4
- data/lib/buzztools/extend_hash.rb +0 -4
- data/lib/buzztools/extend_more.rb +0 -12
- data/lib/buzztools/extend_string.rb +0 -14
- data/lib/buzztools/extras/logging.rb +117 -0
- data/lib/buzztools/{versionary.rb → extras/versionary.rb} +1 -0
- data/lib/buzztools/shell.rb +19 -0
- data/lib/buzztools/to_nil.rb +64 -0
- data/lib/buzztools/version.rb +1 -1
- metadata +10 -18
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OWE5MTlhNmY0NzQ0ZjU4MmEwNjBlZTRhNmEzOWMwYTdmOTY3YWI0NQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MjA1NGY4MjY2NTUyYWY5NWM2MTU1YWU1NDMxMjg2MzkxNTFlZDE2Ng==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDYyMWY1ZDk4NTIyZWY5ZjU3ODExZGI2M2U3YTQyNzI0ZDEzNzhmMDgyNGZl
|
10
|
+
MmZjZjZjOTA2NDIxNDU3ZWUxNDRkZjYxYThhZGNhZWU4NDliYmNlZDYwYTBk
|
11
|
+
MWQ2MWU4ZjQ5ZDQ1MGJiMDcxMTQzOTdmMjA5ZmYyYWUzOWRmNjA=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjI2ZTk3OGQ5ZDIwZGJhMzBhNzY2NmE4NzVlNjQ2ZjI0NjkyY2RkNjk3ZWM5
|
14
|
+
MjgwY2IwYzU0NmEzZWM0OTgyM2EzOGU1NjAyYTQ1MGM4NDczZTdhOGQ2OWZh
|
15
|
+
ODY4MzY0YmEyMmQxY2VhYWE5ZDk4MWE0NjE1MWE3ODE2YzEyODA=
|
@@ -1,19 +1,11 @@
|
|
1
1
|
Bignum.class_eval do
|
2
2
|
|
3
|
-
def to_nil
|
4
|
-
self==0 ? nil : self
|
5
|
-
end
|
6
|
-
|
7
3
|
def to_b(aDefault=false)
|
8
4
|
self==0 ? false : true
|
9
5
|
end
|
10
6
|
|
11
7
|
end
|
12
8
|
|
13
|
-
Float.class_eval do
|
14
|
-
|
15
|
-
|
16
|
-
(self==0 || !self.finite?) ? nil : self
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
9
|
+
# Float.class_eval do
|
10
|
+
#
|
11
|
+
# end
|
@@ -1,9 +1,5 @@
|
|
1
1
|
NilClass.class_eval do
|
2
2
|
|
3
|
-
def to_nil
|
4
|
-
nil
|
5
|
-
end
|
6
|
-
|
7
3
|
def to_b(aDefault=false)
|
8
4
|
false
|
9
5
|
end
|
@@ -16,10 +12,6 @@ end
|
|
16
12
|
|
17
13
|
TrueClass.class_eval do
|
18
14
|
|
19
|
-
def to_nil
|
20
|
-
self
|
21
|
-
end
|
22
|
-
|
23
15
|
def to_b(aDefault=false)
|
24
16
|
self
|
25
17
|
end
|
@@ -28,10 +20,6 @@ end
|
|
28
20
|
|
29
21
|
FalseClass.class_eval do
|
30
22
|
|
31
|
-
def to_nil
|
32
|
-
nil
|
33
|
-
end
|
34
|
-
|
35
23
|
def to_b(aDefault=false)
|
36
24
|
self
|
37
25
|
end
|
@@ -153,15 +153,6 @@ String.class_eval do
|
|
153
153
|
result
|
154
154
|
end
|
155
155
|
|
156
|
-
def to_nil(aPattern=nil)
|
157
|
-
return nil if self.empty?
|
158
|
-
if aPattern
|
159
|
-
return nil if (aPattern.is_a? Regexp) && (self =~ aPattern)
|
160
|
-
return nil if aPattern.to_s == self
|
161
|
-
end
|
162
|
-
self
|
163
|
-
end
|
164
|
-
|
165
156
|
def to_b(aDefault=false)
|
166
157
|
return true if ['1','yes','y','true','on'].include?(self.downcase)
|
167
158
|
return false if ['0','no','n','false','off'].include?(self.downcase)
|
@@ -233,8 +224,3 @@ String.class_eval do
|
|
233
224
|
end
|
234
225
|
|
235
226
|
|
236
|
-
Symbol.class_eval do
|
237
|
-
def to_nil
|
238
|
-
self
|
239
|
-
end
|
240
|
-
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module Buzztools
|
2
|
+
|
3
|
+
lgr = (defined? ActiveSupport::BufferedLogger) ? ActiveSupport::BufferedLogger : Logger
|
4
|
+
|
5
|
+
|
6
|
+
# The default level is DEBUG to pass all output to the sub-loggers, but the sub-loggers level will also determine what is output to their destinations
|
7
|
+
class MultiLogger < Logger
|
8
|
+
|
9
|
+
attr_reader :loggers
|
10
|
+
# if !self.instance_methods.include?(:formatter)
|
11
|
+
# def formatter
|
12
|
+
# @formatter ||= Logger::Formatter.new
|
13
|
+
# end
|
14
|
+
# attr_writer :formatter
|
15
|
+
# end
|
16
|
+
|
17
|
+
def initialize(aLoggers)
|
18
|
+
super(nil)
|
19
|
+
@level = Severity::DEBUG
|
20
|
+
@loggers = aLoggers.is_a?(Array) ? aLoggers : [aLoggers]
|
21
|
+
end
|
22
|
+
|
23
|
+
def add(severity, message = nil, progname = nil, &block)
|
24
|
+
return true if !@loggers
|
25
|
+
severity ||= UNKNOWN
|
26
|
+
@loggers.each do |lr|
|
27
|
+
block_given? ? lr.add(severity, message, progname, &block) : lr.add(severity, message, progname)
|
28
|
+
end
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
alias log add
|
33
|
+
|
34
|
+
def <<(msg)
|
35
|
+
@loggers.each do |lr|
|
36
|
+
lr << msg
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def close
|
41
|
+
@loggers.each do |lr|
|
42
|
+
lr.close
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
#DEBUG D
|
49
|
+
#INFO
|
50
|
+
#WARN ?
|
51
|
+
#ERROR !
|
52
|
+
#FATAL F
|
53
|
+
#UNKNOWN U
|
54
|
+
|
55
|
+
# Logger that mostly works like a STDOUT logger, except that warnings and above get sent to STDERR instead
|
56
|
+
|
57
|
+
class ConsoleLogger < lgr
|
58
|
+
|
59
|
+
class ReportFormatter < Logger::Formatter
|
60
|
+
def call(severity, time, progname, msg)
|
61
|
+
msg2str(msg)+"\n"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def initialize(aErrLevel = Severity::WARN)
|
66
|
+
super(STDOUT)
|
67
|
+
self.formatter = ReportFormatter.new
|
68
|
+
self.level = Severity::INFO
|
69
|
+
self << "\n"
|
70
|
+
@err_logger = Logger.new(STDERR)
|
71
|
+
@err_level = aErrLevel
|
72
|
+
@err_logger.formatter = ReportFormatter.new
|
73
|
+
end
|
74
|
+
|
75
|
+
if !self.instance_methods.include?(:formatter)
|
76
|
+
def formatter
|
77
|
+
@formatter ||= Logger::Formatter.new
|
78
|
+
end
|
79
|
+
attr_writer :formatter
|
80
|
+
end
|
81
|
+
|
82
|
+
alias_method :orig_add, :add
|
83
|
+
|
84
|
+
def add(severity, message = nil, progname = nil, &block)
|
85
|
+
if severity >= @err_level
|
86
|
+
block_given? ? @err_logger.add(severity, message, progname, &block) : @err_logger.add(severity, message, progname)
|
87
|
+
else
|
88
|
+
block_given? ? orig_add(severity, message, progname, &block) : orig_add(severity, message, progname)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
alias log add
|
93
|
+
|
94
|
+
def <<(msg)
|
95
|
+
dev = if self.class.superclass==ActiveSupport::BufferedLogger
|
96
|
+
@log_dest
|
97
|
+
else
|
98
|
+
@logdev
|
99
|
+
end
|
100
|
+
unless dev.nil?
|
101
|
+
dev.write(msg)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
def close
|
107
|
+
begin
|
108
|
+
@logdev.close if @logdev
|
109
|
+
ensure
|
110
|
+
@err_logger.close
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Buzztools
|
2
|
+
module Shell
|
3
|
+
module_function
|
4
|
+
|
5
|
+
# from whenever crontab
|
6
|
+
#/bin/bash -l -c 'cd /var/www/homeopen.com/releases/20140714092436 && bin/rails runner -e production '\''scripts/update_contacts.rb'\'' >> log/cron.log 2>&1'
|
7
|
+
|
8
|
+
def run(aCommand)
|
9
|
+
`/bin/bash -l -c 'cd "#{Rails.root.to_s}" && #{aCommand} 2>&1'` # bin/rails runner -e production '\''scripts/update_contacts.rb'\'' >> log/cron.log 2>&1'`
|
10
|
+
end
|
11
|
+
|
12
|
+
def runner(aScript,*args)
|
13
|
+
pars = (args || []).join(' ')
|
14
|
+
cmd = "rails runner -e #{Rails.env} #{aScript}"
|
15
|
+
cmd += ' ' + pars if pars
|
16
|
+
run(cmd)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
Array.class_eval do
|
2
|
+
def to_nil
|
3
|
+
self.empty? ? nil : self
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
Bignum.class_eval do
|
8
|
+
def to_nil
|
9
|
+
self==0 ? nil : self
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Float.class_eval do
|
14
|
+
def to_nil
|
15
|
+
(self==0 || !self.finite?) ? nil : self
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Fixnum.class_eval do
|
20
|
+
def to_nil
|
21
|
+
self==0 ? nil : self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
Hash.class_eval do
|
26
|
+
def to_nil
|
27
|
+
self.empty? ? nil : self
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
TrueClass.class_eval do
|
32
|
+
def to_nil
|
33
|
+
self
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
FalseClass.class_eval do
|
38
|
+
def to_nil
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
NilClass.class_eval do
|
44
|
+
def to_nil
|
45
|
+
nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Symbol.class_eval do
|
50
|
+
def to_nil
|
51
|
+
self
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
String.class_eval do
|
56
|
+
def to_nil(aPattern=nil)
|
57
|
+
return nil if self.empty?
|
58
|
+
if aPattern
|
59
|
+
return nil if (aPattern.is_a? Regexp) && (self =~ aPattern)
|
60
|
+
return nil if aPattern.to_s == self
|
61
|
+
end
|
62
|
+
self
|
63
|
+
end
|
64
|
+
end
|
data/lib/buzztools/version.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buzztools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.7
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Gary McGhee
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-11-24 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -66,39 +61,36 @@ files:
|
|
66
61
|
- lib/buzztools/extend_object.rb
|
67
62
|
- lib/buzztools/extend_string.rb
|
68
63
|
- lib/buzztools/extend_time.rb
|
64
|
+
- lib/buzztools/extras/logging.rb
|
69
65
|
- lib/buzztools/extras/shell_extras.rb
|
66
|
+
- lib/buzztools/extras/versionary.rb
|
70
67
|
- lib/buzztools/file.rb
|
68
|
+
- lib/buzztools/shell.rb
|
69
|
+
- lib/buzztools/to_nil.rb
|
71
70
|
- lib/buzztools/version.rb
|
72
|
-
- lib/buzztools/versionary.rb
|
73
71
|
homepage: https://github.com/buzzware/buzztools
|
74
72
|
licenses:
|
75
73
|
- MIT
|
74
|
+
metadata: {}
|
76
75
|
post_install_message:
|
77
76
|
rdoc_options: []
|
78
77
|
require_paths:
|
79
78
|
- lib
|
80
79
|
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
80
|
requirements:
|
83
81
|
- - ! '>='
|
84
82
|
- !ruby/object:Gem::Version
|
85
83
|
version: '0'
|
86
|
-
segments:
|
87
|
-
- 0
|
88
|
-
hash: 2474753617006984353
|
89
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
85
|
requirements:
|
92
86
|
- - ! '>='
|
93
87
|
- !ruby/object:Gem::Version
|
94
88
|
version: '0'
|
95
|
-
segments:
|
96
|
-
- 0
|
97
|
-
hash: 2474753617006984353
|
98
89
|
requirements: []
|
99
90
|
rubyforge_project:
|
100
|
-
rubygems_version:
|
91
|
+
rubygems_version: 2.2.2
|
101
92
|
signing_key:
|
102
|
-
specification_version:
|
93
|
+
specification_version: 4
|
103
94
|
summary: reusable function library
|
104
95
|
test_files: []
|
96
|
+
has_rdoc:
|