ripl-rc 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,11 @@
1
1
  = ripl-rc changes history
2
2
 
3
- == ripl-rc 0.1.0 -- ?
3
+ == ripl-rc 0.1.1 -- 2011-02-24
4
+
5
+ * [ plugin] added strip_backtrace
6
+ * [general] now use Ripl::Rc::U.include(YourExtension) to customize details
7
+ * [ color] use Ripl.config[:rc_color] to configure color schema
8
+
9
+ == ripl-rc 0.1.0 -- 2011-02-23
4
10
 
5
11
  * release early, release often
data/README CHANGED
@@ -1,6 +1,6 @@
1
- = ripl-rc 0.1.0
1
+ = ripl-rc 0.1.1
2
2
  by Lin Jen-Shin (godfat[http://godfat.org])
3
- godfat (XD) godfat.org
3
+ godfat (XD) godfat.org
4
4
 
5
5
  == LINKS:
6
6
 
@@ -17,6 +17,7 @@ ripl plugins collection
17
17
  * require 'ripl/rc/ctrld_newline'
18
18
  * require 'ripl/rc/eat_whites'
19
19
  * require 'ripl/rc/color'
20
+ * require 'ripl/rc/strip_backtrace'
20
21
  * require 'ripl/rc' # for all of above
21
22
 
22
23
  == REQUIREMENTS:
@@ -31,7 +32,7 @@ ripl plugins collection
31
32
 
32
33
  Apache License 2.0
33
34
 
34
- Copyright (c) 2010, Cardinal Blue
35
+ Copyright (c) 2010, Lin Jen-Shin (godfat)
35
36
 
36
37
  Licensed under the Apache License, Version 2.0 (the "License");
37
38
  you may not use this file except in compliance with the License.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
- = ripl-rc 0.1.0
1
+ = ripl-rc 0.1.1
2
2
  by Lin Jen-Shin (godfat[http://godfat.org])
3
- godfat (XD) godfat.org
3
+ godfat (XD) godfat.org
4
4
 
5
5
  == LINKS:
6
6
 
@@ -17,6 +17,7 @@ ripl plugins collection
17
17
  * require 'ripl/rc/ctrld_newline'
18
18
  * require 'ripl/rc/eat_whites'
19
19
  * require 'ripl/rc/color'
20
+ * require 'ripl/rc/strip_backtrace'
20
21
  * require 'ripl/rc' # for all of above
21
22
 
22
23
  == REQUIREMENTS:
@@ -31,7 +32,7 @@ ripl plugins collection
31
32
 
32
33
  Apache License 2.0
33
34
 
34
- Copyright (c) 2010, Cardinal Blue
35
+ Copyright (c) 2010, Lin Jen-Shin (godfat)
35
36
 
36
37
  Licensed under the Apache License, Version 2.0 (the "License");
37
38
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -1,6 +1,42 @@
1
1
 
2
- require 'bundler'
3
- Bundler::GemHelper.install_tasks
2
+ gemspec = "#{File.dirname(__FILE__)}/ripl-rc.gemspec"
3
+
4
+ if File.exist?(gemspec) && File.read(gemspec).strip != ''
5
+ require 'bundler'
6
+ # please do me a favor, don't use thor!!
7
+ b = Bundler::GemHelper.new(File.dirname(__FILE__))
8
+ Bundler::GemHelper.send(:public, :name, :version, :version_tag)
9
+
10
+ desc "Build #{b.name}-#{b.version}.gem into the pkg directory"
11
+ task :build => [:gemspec] do
12
+ b.build_gem
13
+ end
14
+
15
+ desc "Build and install #{b.name}-#{b.version}.gem into system gems"
16
+ task :install => [:gemspec] do
17
+ b.install_gem
18
+ end
19
+
20
+ desc "Create tag #{b.version_tag} and build and push " \
21
+ "#{b.name}-#{b.version}.gem to Rubygems"
22
+ task :release => [:check_version, :gemspec] do
23
+ b.release_gem
24
+ end
25
+
26
+ task :check_version do
27
+ if ENV['VERSION'].nil?
28
+ puts("\x1b[33mPlease provide " \
29
+ "\x1b[36mVERSION\x1b[33m=\x1b[36mx.y.z\x1b[m")
30
+ exit(1)
31
+
32
+ elsif ENV['VERSION'] != b.version.to_s
33
+ puts("\x1b[33mYou gave \x1b[36mVERSION\x1b[33m=\x1b[36m#{b.version} " \
34
+ "\x1b[33mbut got\n \x1b[36m" \
35
+ "VERSION\x1b[33m=\x1b[36m#{ENV['VERSION']}\x1b[m")
36
+ exit(2)
37
+ end
38
+ end
39
+ end
4
40
 
5
41
  desc 'Run tests'
6
42
  task :test do
@@ -9,7 +45,39 @@ end
9
45
 
10
46
  desc 'Generate gemspec'
11
47
  task :gemspec do
48
+ require 'pathname'
12
49
  require 'ripl/rc/version'
50
+
51
+ def dir
52
+ @dir ||= File.dirname(__FILE__)
53
+ end
54
+
55
+ def to_regexpes pathes
56
+ pathes.map{ |ignore|
57
+ if ignore =~ /\*/
58
+ to_regexpes(Dir["**/#{ignore}"])
59
+ else
60
+ Regexp.new("^#{Regexp.escape(ignore)}")
61
+ end
62
+ }.flatten
63
+ end
64
+
65
+ def ignore_files
66
+ @ignore_files ||= to_regexpes(
67
+ File.read("#{dir}/.gitignore").split("\n") + ['.git/'])
68
+ end
69
+
70
+ def gem_files
71
+ @gem_files ||= gem_files_find(Pathname.new(File.dirname(__FILE__)))
72
+ end
73
+
74
+ def gem_files_find path
75
+ path.children.select(&:file?).map{ |file| file.to_s[(dir.size+1)..-1] }.
76
+ reject{ |file| ignore_files.find{ |ignore| file.to_s =~ ignore }} +
77
+
78
+ path.children.select(&:directory?).map{ |dir| gem_files_find(dir)}.flatten
79
+ end
80
+
13
81
  File.open('ripl-rc.gemspec', 'w'){ |f|
14
82
  f <<
15
83
  Gem::Specification.new do |s|
@@ -17,6 +85,9 @@ task :gemspec do
17
85
  s.version = Ripl::Rc::VERSION
18
86
 
19
87
  s.add_dependency('ripl')
88
+ %w[bacon rr].each{ |g|
89
+ s.add_development_dependency(g)
90
+ }
20
91
 
21
92
  s.authors = ['Lin Jen-Shin (godfat)']
22
93
  s.email = ['godfat (XD) godfat.org']
@@ -27,8 +98,8 @@ task :gemspec do
27
98
 
28
99
  s.date = Time.now.strftime('%Y-%m-%d')
29
100
  s.rubygems_version = Gem::VERSION
30
- s.files = `git ls-files`.split("\n")
31
- s.test_files = `git ls-files -- test/test_*.rb`.split("\n")
101
+ s.files = gem_files
102
+ s.test_files = gem_files.grep(/test_.+?\.rb$/)
32
103
  s.extra_rdoc_files = ['CHANGES', 'README', "#{s.name}.gemspec"]
33
104
  s.rdoc_options = ['--main', 'README']
34
105
  s.require_paths = ['lib']
data/lib/ripl/rc/color.rb CHANGED
@@ -3,54 +3,63 @@ require 'ripl'
3
3
 
4
4
  module Ripl::Rc; end
5
5
  module Ripl::Rc::Color
6
- def format_result result
7
- colors = {
8
- String => :green ,
9
- Numeric => :red ,
10
- Symbol => :cyan ,
11
- Array => :blue ,
12
- Hash => :blue ,
13
- NilClass => :magenta,
14
- TrueClass => :magenta,
15
- FalseClass => :magenta,
16
- Object => :yellow
17
- }
6
+ include Ripl::Rc # makes U avaliable
18
7
 
8
+ def format_result result
19
9
  case result
20
- when String ; send(colors[String ]){ "'#{result}'" }
21
- when Numeric; send(colors[Numeric ]){ result }
22
- when Symbol ; send(colors[Symbol ]){ ":#{result}" }
23
- when Array ; send(colors[Array ]){ '[' } +
24
- result.map{ |e| format_result(e) }.join(
25
- send(colors[Array ]){ ', ' }) +
26
- send(colors[Array ]){ ']' }
27
- when Hash ; send(colors[Hash ]){ '{' } +
28
- result.map{ |k, v| format_result(k) +
29
- send(colors[Hash ]){ '=>' } +
10
+ when String ; U.send(U.colors[String ]){ "'#{result}'" }
11
+ when Numeric; U.send(U.colors[Numeric ]){ result }
12
+ when Symbol ; U.send(U.colors[Symbol ]){ ":#{result}" }
13
+ when Array ; U.send(U.colors[Array ]){ '[' } +
14
+ result.map{ |e| format_result(e) }.join(
15
+ U.send(U.colors[Array ]){ ', ' }) +
16
+ U.send(U.colors[Array ]){ ']' }
17
+ when Hash ; U.send(U.colors[Hash ]){ '{' } +
18
+ result.map{ |k, v| format_result(k) +
19
+ U.send(U.colors[Hash ]){ '=>' } +
30
20
  format_result(v) }.join(
31
- send(colors[Hash ]){ ', ' }) +
32
- send(colors[Hash ]){ '}' }
33
- else ; if colors[result.class]
34
- send(colors[result.class]){ result.inspect }
21
+ U.send(U.colors[Hash ]){ ', ' }) +
22
+ U.send(U.colors[Hash ]){ '}' }
23
+ else ; if U.colors[result.class]
24
+ U.send(U.colors[result.class]){ result.inspect }
35
25
  else
36
- send(colors[Object ]){ result.inspect }
26
+ U.send(U.colors[Object ]){ result.inspect }
37
27
  end
38
28
  end
39
29
  end
40
30
 
41
- def color rgb
42
- "\x1b[#{rgb}m" + (block_given? ? "#{yield}#{reset}" : '')
43
- end
31
+ module Imp
32
+ def colors
33
+ Ripl.config[:rc_color]
34
+ end
44
35
 
45
- def black &block; color(30, &block); end
46
- def red &block; color(31, &block); end
47
- def green &block; color(32, &block); end
48
- def yellow &block; color(33, &block); end
49
- def blue &block; color(34, &block); end
50
- def magenta &block; color(35, &block); end
51
- def cyan &block; color(36, &block); end
52
- def white &block; color(37, &block); end
53
- def reset &block; color('', &block); end
36
+ def color rgb
37
+ "\x1b[#{rgb}m" + (block_given? ? "#{yield}#{reset}" : '')
38
+ end
39
+
40
+ def black &block; color(30, &block); end
41
+ def red &block; color(31, &block); end
42
+ def green &block; color(32, &block); end
43
+ def yellow &block; color(33, &block); end
44
+ def blue &block; color(34, &block); end
45
+ def magenta &block; color(35, &block); end
46
+ def cyan &block; color(36, &block); end
47
+ def white &block; color(37, &block); end
48
+ def reset &block; color('', &block); end
49
+ end
54
50
  end
55
51
 
52
+ module Ripl::Rc::U; extend Ripl::Rc::Color::Imp; end
53
+
56
54
  Ripl::Shell.include(Ripl::Rc::Color)
55
+ Ripl.config[:rc_color] ||= {
56
+ String => :green ,
57
+ Numeric => :red ,
58
+ Symbol => :cyan ,
59
+ Array => :blue ,
60
+ Hash => :blue ,
61
+ NilClass => :magenta,
62
+ TrueClass => :magenta,
63
+ FalseClass => :magenta,
64
+ Object => :yellow
65
+ }
@@ -1,4 +1,7 @@
1
1
 
2
+ require 'ripl'
3
+
4
+ module Ripl::Rc; end
2
5
  module Ripl::Rc::CtrldNewline
3
6
  # make ctrl-d end with a newline
4
7
  def after_loop
@@ -3,9 +3,13 @@ require 'ripl'
3
3
 
4
4
  module Ripl::Rc; end
5
5
  module Ripl::Rc::SqueezeHistory
6
+ include Ripl::Rc # makes U avaliable
7
+
6
8
  # write squeezed history
7
9
  def write_history
8
- File.open(history_file, 'w'){ |f| f.puts squeeze_history.join("\n") }
10
+ File.open(history_file, 'w'){ |f|
11
+ f.puts U.squeeze_history(history).join("\n")
12
+ }
9
13
  end
10
14
 
11
15
  # squeeze history on memory too
@@ -15,15 +19,19 @@ module Ripl::Rc::SqueezeHistory
15
19
  super
16
20
  end
17
21
 
18
- def squeeze_history
19
- history.to_a.inject([]){ |result, item|
20
- if result.last == item
21
- result
22
- else
23
- result << item
24
- end
25
- }
22
+ module Imp
23
+ def squeeze_history history
24
+ history.to_a.inject([]){ |result, item|
25
+ if result.last == item
26
+ result
27
+ else
28
+ result << item
29
+ end
30
+ }
31
+ end
26
32
  end
27
33
  end
28
34
 
35
+ module Ripl::Rc::U; extend Ripl::Rc::SqueezeHistory::Imp; end
36
+
29
37
  Ripl::Shell.include(Ripl::Rc::SqueezeHistory)
@@ -0,0 +1,35 @@
1
+
2
+ require 'ripl'
3
+
4
+ module Ripl::Rc; end
5
+ module Ripl::Rc::StripBacktrace
6
+ include Ripl::Rc # makes U avaliable
7
+
8
+ # strip backtrace until ripl
9
+ def format_error e
10
+ "#{e.class}: #{e.message}\n #{U.strip_backtrace(e).join("\n ")}"
11
+ end
12
+
13
+ module Imp
14
+ def strip_backtrace e
15
+ home(cwd(snip(e)))
16
+ end
17
+
18
+ def home b
19
+ b.map{ |p| p.sub(ENV['HOME'], '~') }
20
+ end
21
+
22
+ def cwd b
23
+ b.map{ |p| p.sub(Dir.pwd, './') }
24
+ end
25
+
26
+ def snip e
27
+ e.backtrace[0..e.backtrace.rindex{ |l| l =~ /\(ripl\):\d+:in `.+?'/ } ||
28
+ -1]
29
+ end
30
+ end
31
+ end
32
+
33
+ module Ripl::Rc::U; extend Ripl::Rc::StripBacktrace::Imp; end
34
+
35
+ Ripl::Shell.include(Ripl::Rc::StripBacktrace)
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Ripl
3
3
  module Rc
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
6
6
  end
data/lib/ripl/rc.rb CHANGED
@@ -3,3 +3,4 @@ require 'ripl/rc/squeeze_history'
3
3
  require 'ripl/rc/ctrld_newline'
4
4
  require 'ripl/rc/eat_whites'
5
5
  require 'ripl/rc/color'
6
+ require 'ripl/rc/strip_backtrace'
data/ripl-rc.gemspec CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ripl-rc}
5
- s.version = "0.1.0"
5
+ s.version = "0.1.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Lin Jen-Shin (godfat)"]
9
- s.date = %q{2011-02-23}
9
+ s.date = %q{2011-02-24}
10
10
  s.description = %q{ripl plugins collection}
11
11
  s.email = ["godfat (XD) godfat.org"]
12
12
  s.extra_rdoc_files = ["CHANGES", "README", "ripl-rc.gemspec"]
13
- s.files = [".gitignore", "CHANGES", "Gemfile", "LICENSE", "README", "README.rdoc", "Rakefile", "TODO", "lib/ripl/rc.rb", "lib/ripl/rc/color.rb", "lib/ripl/rc/ctrld_newline.rb", "lib/ripl/rc/eat_whites.rb", "lib/ripl/rc/squeeze_history.rb", "lib/ripl/rc/version.rb", "ripl-rc.gemspec", "test/test_squeeze_history.rb"]
13
+ s.files = [".gitignore", "CHANGES", "Gemfile", "LICENSE", "README", "README.rdoc", "Rakefile", "TODO", "ripl-rc.gemspec", "lib/ripl/rc.rb", "lib/ripl/rc/color.rb", "lib/ripl/rc/ctrld_newline.rb", "lib/ripl/rc/eat_whites.rb", "lib/ripl/rc/squeeze_history.rb", "lib/ripl/rc/strip_backtrace.rb", "lib/ripl/rc/version.rb", "test/test_squeeze_history.rb"]
14
14
  s.homepage = %q{http://github.com/godfat/ripl-rc}
15
15
  s.rdoc_options = ["--main", "README"]
16
16
  s.require_paths = ["lib"]
@@ -23,10 +23,16 @@ Gem::Specification.new do |s|
23
23
 
24
24
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
25
  s.add_runtime_dependency(%q<ripl>, [">= 0"])
26
+ s.add_development_dependency(%q<bacon>, [">= 0"])
27
+ s.add_development_dependency(%q<rr>, [">= 0"])
26
28
  else
27
29
  s.add_dependency(%q<ripl>, [">= 0"])
30
+ s.add_dependency(%q<bacon>, [">= 0"])
31
+ s.add_dependency(%q<rr>, [">= 0"])
28
32
  end
29
33
  else
30
34
  s.add_dependency(%q<ripl>, [">= 0"])
35
+ s.add_dependency(%q<bacon>, [">= 0"])
36
+ s.add_dependency(%q<rr>, [">= 0"])
31
37
  end
32
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ripl-rc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-02-23 00:00:00.000000000 +08:00
12
+ date: 2011-02-24 00:00:00.000000000 +08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ripl
17
- requirement: &2152443260 !ruby/object:Gem::Requirement
17
+ requirement: &2152294800 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,7 +22,29 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2152443260
25
+ version_requirements: *2152294800
26
+ - !ruby/object:Gem::Dependency
27
+ name: bacon
28
+ requirement: &2152262760 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *2152262760
37
+ - !ruby/object:Gem::Dependency
38
+ name: rr
39
+ requirement: &2152171240 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2152171240
26
48
  description: ripl plugins collection
27
49
  email:
28
50
  - godfat (XD) godfat.org
@@ -41,13 +63,14 @@ files:
41
63
  - README.rdoc
42
64
  - Rakefile
43
65
  - TODO
66
+ - ripl-rc.gemspec
44
67
  - lib/ripl/rc.rb
45
68
  - lib/ripl/rc/color.rb
46
69
  - lib/ripl/rc/ctrld_newline.rb
47
70
  - lib/ripl/rc/eat_whites.rb
48
71
  - lib/ripl/rc/squeeze_history.rb
72
+ - lib/ripl/rc/strip_backtrace.rb
49
73
  - lib/ripl/rc/version.rb
50
- - ripl-rc.gemspec
51
74
  - test/test_squeeze_history.rb
52
75
  has_rdoc: true
53
76
  homepage: http://github.com/godfat/ripl-rc