ro_support 0.0.4 → 0.0.5

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: 6ccdfe67cf1f839c8b160b26ecdf42c8a7691c80
4
- data.tar.gz: 2a9fa9bf87372a4cea22c55da0d835d13641041d
3
+ metadata.gz: 1a38c2fd59e24c7617654ef3ecbb7e8920b4ee13
4
+ data.tar.gz: d24a30b59180aebf70fc1b1b3dde8f65f1805bc1
5
5
  SHA512:
6
- metadata.gz: 5907695c8501a6581d4a801b9e465d553865584164caa1bb71fdd4dd89c60d40bfd900154c9ecf60743534f9dbcdfffdeffeb46aadd69d5e054f8a8240e6ac28
7
- data.tar.gz: 56f7547893d0ffaa353719a3a08bc9a23191165d7c415f43793e52f531dc121ef00894f7446bd0a2923bd4fc5bd83be59229f124b0edc541de4e1883f00bc382
6
+ metadata.gz: 983f6b234912ef1d6c482cd34a18a60f4f45297a34f88ad5adf6571ef13b31d5895f1fa3d98245c83508263d48365c95dd348e7cf76e26be51b9bab3a66bb810
7
+ data.tar.gz: c6a1747b3bcbece3de0662612d922afcffd6fd66adbae88ef33ef5bc5d2c17b810c19c6f5bab0ff3538d324b76a71e6b8fb1d68eb0f4dfad0c92e7b92bd4c088
@@ -4,6 +4,17 @@ module RoSupport
4
4
  def self.included(base)
5
5
  base.send(:alias_method, :ro_raise, :eval)
6
6
  base.send(:alias_method, :ro_return, :eval)
7
+ base.send(:alias_method, :ro_print, :eval)
8
+ end
9
+
10
+ def vars(*lvars)
11
+
12
+ print_str = []
13
+ lvars.each do |var_name|
14
+ print_str << "p '#{var_name}:' + #{var_name}"
15
+ end
16
+
17
+ print_str.join(";")
7
18
  end
8
19
 
9
20
  def err(msg='error', opt={output: []})
@@ -1,8 +1,16 @@
1
- require 'logger'
1
+
2
2
  module RoSupport
3
3
  module Log
4
- def raise_log(content, log_file='ro.log')
5
- raise err=content if content.is_a?(Exception)
4
+
5
+ def puts_log(content, log_file='ro.log')
6
+ if content.is_a?(Exception)
7
+ puts ""
8
+ puts(ANSI.red "#{err=content}")
9
+ err.backtrace.map do |line|
10
+ line[/rvm/] ? puts(ANSI.green { line }) : puts(ANSI.blue { line })
11
+ end
12
+ end
13
+
6
14
  if defined?(Rails) && defined?(Rails.root)
7
15
  log = Logger.new("#{Rails.root}/log/#{log_file}")
8
16
  log.error(content)
@@ -1,5 +1,5 @@
1
1
  require 'active_support/core_ext/string'
2
- dirname =__FILE__.gsub /\.rb/, ''
2
+ dirname =__FILE__.gsub /\.rb$/, ''
3
3
 
4
4
  Dir[File.join dirname, "**"].each do |file|
5
5
  require file
@@ -1,6 +1,14 @@
1
1
  require 'active_support/core_ext/string'
2
2
 
3
- dirname = __FILE__.gsub /\.rb/, ''
3
+ module RoSupport
4
+ module StringHandler
5
+ def self.get_dirname_same_with(file)
6
+ file.gsub /\.rb$/, ''
7
+ end
8
+ end
9
+ end
10
+
11
+ dirname = RoSupport::StringHandler.get_dirname_same_with __FILE__
4
12
 
5
13
  Dir[File.join dirname, "**"].each do |file|
6
14
  require file
@@ -11,3 +19,4 @@ module RoSupport
11
19
  include Common
12
20
  end
13
21
  end
22
+
@@ -1,3 +1,3 @@
1
1
  module RoSupport
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/ro_support.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'active_support/core_ext/string'
2
2
  require 'thor'
3
3
  require 'nokogiri'
4
+ require 'logger'
5
+ require 'ansi'
4
6
 
5
7
  $LOAD_PATH.unshift File.expand_path("../..", __FILE__)
6
8
  # autoload
@@ -1,2 +1,2 @@
1
- # Logfile created on 2013-09-24 20:48:53 +0800 by logger.rb/36483
2
- E, [2013-09-24T20:48:53.874180 #22041] ERROR -- : Nisi voluptatum rem atque maxime quos fugiat quo. Optio minima voluptate maiores perferendis voluptates. Quam vitae nisi facere et sit.
1
+ # Logfile created on 2013-09-30 21:02:45 +0800 by logger.rb/36483
2
+ E, [2013-09-30T21:02:45.567382 #17790] ERROR -- : Harum accusamus minus quo modi aut iste repudiandae. Ex omnis reprehenderit ut qui. Cumque adipisci veniam.
@@ -13,13 +13,19 @@ class C
13
13
  def try_ro_raise
14
14
  foo = 'foo'
15
15
  bar = 'bar'
16
- ro_raise err('msg', output:['@foo', '@bar', 'bar', 'foo'])
16
+ ro_raise err('msg', output: ['@foo', '@bar', 'bar', 'foo'])
17
17
  end
18
18
 
19
- def try_ro_return
19
+ #def try_ro_return
20
+ # foo = 'foo'
21
+ # bar = 'bar'
22
+ # ro_return valid(nil, output:['foo', 'bar'])
23
+ #end
24
+
25
+ def try_ro_print
20
26
  foo = 'foo'
21
27
  bar = 'bar'
22
- ro_return valid(nil, output:['foo', 'bar'])
28
+ ro_print vars('foo', 'bar')
23
29
  end
24
30
  end
25
31
 
@@ -32,11 +38,15 @@ describe Debug do
32
38
  end.to raise_error RuntimeError
33
39
  end
34
40
 
35
- describe 'ro_return' do
36
- it 'raise error when return a invalid argument' do
37
- expect do
38
- c.try_ro_return
39
- end.to raise_error RuntimeError
40
- end
41
+ #describe 'ro_return' do
42
+ # it 'raise error when return a invalid argument' do
43
+ # expect do
44
+ # c.try_ro_return
45
+ # end.to raise_error RuntimeError
46
+ # end
47
+ #end
48
+
49
+ it 'ro_print' do
50
+ expect(c.try_ro_print).to be == "bar:bar"
41
51
  end
42
52
  end
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+
2
3
  include Log
3
4
 
4
5
  describe Log do
@@ -7,9 +8,21 @@ describe Log do
7
8
  `rm -r ./*`
8
9
  end
9
10
 
10
- it 'raise_log(log_file, *contents)' do
11
- content = Faker::Lorem.paragraph
12
- raise_log(content, 'ro.log')
13
- expect(File.read('ro.log')).to match content
11
+ describe 'puts_log(log_file, *contents)' do
12
+ it '' do
13
+ content = Faker::Lorem.paragraph
14
+ puts_log(content, 'ro.log')
15
+ expect(File.read('ro.log')).to match content
16
+ end
17
+
18
+ it 'content is a Exception' do
19
+ expect do
20
+ begin
21
+ 1/0
22
+ rescue => e
23
+ puts_log(e, 'ro.log')
24
+ end
25
+ end.not_to raise_error
26
+ end
14
27
  end
15
28
  end
@@ -10,6 +10,12 @@ describe StringHandler do
10
10
  expect("ManMan".uncamelize).to match /man_man/
11
11
  end
12
12
 
13
+ it 'get_dirname_same_with file' do
14
+ file = "/home/zxr/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/ro_support-0.0.4/lib/ro_support/misc.rb"
15
+ expect(RoSupport::StringHandler.get_dirname_same_with file).to be ==
16
+ "/home/zxr/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/gems/ro_support-0.0.4/lib/ro_support/misc"
17
+ end
18
+
13
19
  it 'blank?' do
14
20
  expect(' '.blank?).to be_true
15
21
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ro_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-26 00:00:00.000000000 Z
11
+ date: 2013-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: ansi
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: ''
112
126
  email:
113
127
  - zhuxingruo3@gmail.com
@@ -139,6 +153,7 @@ files:
139
153
  - spec/fixtures/sample/try2.rb
140
154
  - spec/fixtures/sample/try3.rb
141
155
  - spec/fixtures/baidu.html
156
+ - spec/fixtures/for_log/tmp/rspec_guard_result
142
157
  - spec/fixtures/for_log/ro.log
143
158
  - spec/fixtures/for_misc_file_utils/create_dir_file/try.rb
144
159
  - spec/spec_helper.rb
@@ -174,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
174
189
  version: '0'
175
190
  requirements: []
176
191
  rubyforge_project:
177
- rubygems_version: 2.0.7
192
+ rubygems_version: 2.1.5
178
193
  signing_key:
179
194
  specification_version: 4
180
195
  summary: ''
@@ -183,6 +198,7 @@ test_files:
183
198
  - spec/fixtures/sample/try2.rb
184
199
  - spec/fixtures/sample/try3.rb
185
200
  - spec/fixtures/baidu.html
201
+ - spec/fixtures/for_log/tmp/rspec_guard_result
186
202
  - spec/fixtures/for_log/ro.log
187
203
  - spec/fixtures/for_misc_file_utils/create_dir_file/try.rb
188
204
  - spec/spec_helper.rb