rmtools 2.4.8 → 2.4.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e8e12082b944e9b2b5448e9fe05a69da97e39b7
4
- data.tar.gz: 32b3623bfcd26012dab4266b25fc9a17cd7fa53c
3
+ metadata.gz: 7e54c98862033d4ec75d2178223ac390eac3cca8
4
+ data.tar.gz: a04c2e1e1fd7fa2d6bcd49d1660b0782faedd4ea
5
5
  SHA512:
6
- metadata.gz: cc3701b9c5bf250d8855f66fddd0a5a43b4605be9f407508fc55eb84c65b60d7da0405f95ede5bf4d96935d99a4e305dba23c9e3a4f53d6a146f24d6aba4fa88
7
- data.tar.gz: d37e09f9fca2c176e77ec84a3547ada06eed0099fc68c479d176c9ba4e11a8fb52398572454d820fc59ce8bef95bb9a733d9056bb3ea0ce84b62e89337ee653b
6
+ metadata.gz: 2e9d1f316fc909aa08a99827aa2de3a24433b53ad9d304e79c71dfedfa43ee15f7aaa36071a3522f0f4e57c731a786b5d84dd06aa5fea19c73e6853686739dd6
7
+ data.tar.gz: da3cbc53ef93298a2c76f42b945fb5a00d1a1250a44c8c72be5af32b9e9b80f2db145cb1653d8ff0a94b88957a588885b1b55b5724e1169038ff5de150c5dd2e
@@ -4,9 +4,41 @@ RMTools::require 'console/coloring'
4
4
  RMTools::require 'text/string_parse'
5
5
 
6
6
  module RMTools
7
-
8
- # lazy logger
9
- # with caller processing and highlighting
7
+ ## Lazy logger
8
+ ## with timer, coloring and caller hints
9
+ # Usage:
10
+ #> $log <= "Starting process..."
11
+ # 13:43:01.632 DEBUG [(irb):1 :irb_binding]: Starting process...
12
+ #> $log << ["Got response:", {code: 200, body: "Hello"}]
13
+ # 13:43:20.524 INFO [(irb):2 :irb_binding]: ["Got response:", {:code=>200, :body=>"Hello"}]
14
+ # $log < "Oops, something went wrong!"
15
+ # 13:43:32.030 WARN [(irb):3 :irb_binding]: Oops, something went wrong!
16
+ #
17
+ # which is aliases of #debug, #info and #warn, consequently
18
+ ##
19
+ # If you want to wrap logger call into another method:
20
+ #> class Exception
21
+ #> def warn!
22
+ #> $log.warn "#{self.class} – #{message}", caller: 2
23
+ #> end
24
+ #> end
25
+ # but still see in log string a reference to that method calling Exeption#warn!
26
+ # just pass stack frames quantity as :caller param
27
+ ##
28
+ # If you want to log an info that need a calculations
29
+ # (remember, #inspect is a calculations as well)
30
+ # to be logged, but don't want a production server
31
+ # to calculate this,
32
+ # you may pass that calculations in a block:
33
+ #> $log.debug {a_large_object}
34
+ # and it won't run if #debug should not run at this moment
35
+ ##
36
+ # Log level might be set for one server or console session using ENV variables:
37
+ # LOGLEVEL={DEBUG | INFO | WARN | ERROR}
38
+ # or
39
+ # DEBUG=1 | WARN=1 | SILENT=1
40
+ # Default log level is INFO
41
+ ##
10
42
  class RMLogger
11
43
  __init__
12
44
  attr_accessor :mute_info, :mute_error, :mute_warn, :mute_log, :mute_debug
@@ -250,6 +282,7 @@ module RMTools
250
282
 
251
283
  end
252
284
 
253
- # default logger now initialized here
285
+ # Default global logger now initialized here
286
+ # I believe it wouldn't hurt you
254
287
  $log = RMLogger.new
255
288
  end
@@ -59,6 +59,10 @@ module RMTools
59
59
  i += 1
60
60
  m = m2
61
61
  end
62
+ # Magic numbers! If a size of a backtrace array > 16 (line count doesn't affect), IRB forgets to print newline after an exception trace! I don't even want to know, why the hell it's going this way!
63
+ if bt.size > 16 and bt.last[-1] != "\n"
64
+ bt.last << "\n"
65
+ end
62
66
  bt
63
67
  end
64
68
 
@@ -57,7 +57,7 @@ class String
57
57
  end
58
58
 
59
59
  private
60
- # Если последний (в итераторе в #split_to_blocks
60
+ # Если последний (в итераторе в #split_to_blocks)
61
61
  # результат #split_by_syntax окажется слишком велик,
62
62
  # он всё равно не будет включен в результат #split_to_blocks.
63
63
  def split_by_syntax(str, maxlen, buflen=0)
@@ -71,7 +71,7 @@ class String
71
71
  add
72
72
  end
73
73
 
74
- def sanitize_blocks!(blocks, maxlen, opts)
74
+ def sanitize_blocks!(blocks, maxlen, terminator, opts)
75
75
  blocks.reject! {|b| b.empty?} if opts[:no_blanks]
76
76
  blocks.strips! if opts[:strips]
77
77
  blocks.each {|b| raise Exception, "can't split string by #{terminator} to blocks with max length = #{maxlen}" if b.size > maxlen} if opts[:strict_overhead]
@@ -85,6 +85,9 @@ class String
85
85
  raise Exception, "Can't split text with maxlen = #{maxlen}" if maxlen < 1
86
86
  return [self] if size <= maxlen
87
87
  terminator, opts = opts.fetch_opts [nil, :flags], :strict_overhead => true, :no_blanks => true
88
+ if opts[:strict_overhead]
89
+ opts[:strips] = true
90
+ end
88
91
  blocks = []
89
92
  term_re = /[^#{terminator}]+\z/ if terminator and terminator != :syntax
90
93
  words, buf = split(opts[:strips] ? ' ' : / /), nil
@@ -105,7 +108,7 @@ class String
105
108
  end
106
109
  end
107
110
  if blocks.size == opts[:lines]
108
- return sanitize_blocks! blocks, maxlen, opts
111
+ return sanitize_blocks! blocks, maxlen, terminator, opts
109
112
  end
110
113
  blocks << ''
111
114
  if buf
@@ -119,7 +122,7 @@ class String
119
122
  buf = nil
120
123
  end
121
124
  end
122
- sanitize_blocks! blocks, maxlen, opts
125
+ sanitize_blocks! blocks, maxlen, terminator, opts
123
126
  end
124
127
 
125
128
  # 'An elegant way to factor duplication out of options passed to a series of method calls. Each method called in the block, with the block variable as the receiver, will have its options merged with the default options hash provided. '.cut_line 100
@@ -138,15 +141,16 @@ class String
138
141
  cuted + '…'
139
142
  end
140
143
  else
141
- def cut_line(maxlen, terminator=:syntax)
144
+ # @ maxlen : сделать строку короче значения,
145
+ # @ terminator :
146
+ # - default = nil : не обрезая слов
147
+ # - :syntax : которая была бы наиболее законченной фразой
148
+ def cut_line(maxlen, terminator=nil)
142
149
  return self if size <= maxlen
143
150
  blocks = split_to_blocks(maxlen-1, terminator, :strips => true, :strict_overhead => false, :lines => 1)
144
151
  cuted = (blocks[0] || self)[0, maxlen]
145
- if terminator == :syntax
146
- cuted.gsub!(/[.!?,;]$/, '')
147
- else cuted.chomp!('.')
148
- end
149
- cuted + '…'
152
+ cuted.gsub!(/[.?!…;,:\n。、]$/, '')
153
+ cuted << ''
150
154
  end
151
155
  end
152
156
 
@@ -1,3 +1,3 @@
1
1
  module RMTools
2
- VERSION = '2.4.8'
2
+ VERSION = '2.4.9'
3
3
  end
@@ -21,7 +21,7 @@ module LibXML::XML
21
21
 
22
22
  FindByProc = lambda {|node, ns, ss|
23
23
  str_to_eval = ss.matched[1..-2]
24
- block = eval "lambda {|_| #{'_' if !str_to_eval['_']}#{str_to_eval}}"
24
+ block = eval "lambda {|_| #{str_to_eval['_'] ? '' : str_to_eval[0] == '[' ? '_' : '_.'}#{str_to_eval}}"
25
25
  node = node.is(Array) ?
26
26
  node.sum([]) {|n| n.__find(nil, ns, ss).select(&block).to_a} :
27
27
  node.__find(nil, ns, ss).select(&block)
@@ -93,4 +93,4 @@ module LibXML::XML
93
93
 
94
94
  end
95
95
 
96
- end
96
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.8
4
+ version: 2.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Baev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
11
+ date: 2015-08-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RMTools is a collection of helpers for debug, text/array/file processing
14
14
  and simply easing a coding process
@@ -19,7 +19,7 @@ extensions:
19
19
  - ext/extconf.rb
20
20
  extra_rdoc_files: []
21
21
  files:
22
- - .gitignore
22
+ - ".gitignore"
23
23
  - Gemfile
24
24
  - LICENSE
25
25
  - README.md
@@ -128,20 +128,19 @@ require_paths:
128
128
  - lib
129
129
  required_ruby_version: !ruby/object:Gem::Requirement
130
130
  requirements:
131
- - - '>='
131
+ - - ">="
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
134
  required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
140
  rubyforge_project:
141
- rubygems_version: 2.4.1
141
+ rubygems_version: 2.2.2
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: Collection of helpers for debug, text/array/file processing and simply easing
145
145
  a coding process
146
146
  test_files: []
147
- has_rdoc: