wrong 0.4.1-java → 0.4.2-java

Sign up to get free protection for your applications and to get access to all the features.
data/lib/wrong/chunk.rb CHANGED
@@ -1,17 +1,16 @@
1
1
  require 'ruby_parser'
2
2
  require 'ruby2ruby'
3
3
 
4
- begin
5
- require "ParseTree"
6
- rescue LoadError => e
7
- raise e unless e.message == "no such file to load -- ParseTree"
4
+ def require_optionally(library)
5
+ begin
6
+ require library
7
+ rescue LoadError => e
8
+ raise e unless e.message == "no such file to load -- #{library}"
9
+ end
8
10
  end
9
11
 
10
- begin
11
- require "sourcify"
12
- rescue LoadError => e
13
- raise e unless e.message == "no such file to load -- sourcify"
14
- end
12
+ require_optionally "ParseTree"
13
+ require_optionally "sourcify"
15
14
 
16
15
  require "wrong/config"
17
16
  require "wrong/sexp_ext"
data/lib/wrong/config.rb CHANGED
@@ -6,6 +6,7 @@ module Wrong
6
6
  Chunk.read_here_or_higher(".wrong")
7
7
  rescue Errno::ENOENT => e
8
8
  # couldn't find it
9
+ nil # In Ruby 1.8, "e" would be returned here otherwise
9
10
  end
10
11
  Config.new settings
11
12
  end
@@ -19,7 +20,8 @@ module Wrong
19
20
  end
20
21
 
21
22
  class Config < Hash
22
- def initialize(string = nil)
23
+ def initialize(string = nil)
24
+ self[:aliases] = {:assert => [:assert], :deny => [:deny]}
23
25
  if string
24
26
  instance_eval string.gsub(/^(.*=)/, "self.\\1")
25
27
  end
@@ -33,22 +35,26 @@ module Wrong
33
35
  self[name.to_sym] = value
34
36
  end
35
37
 
38
+ def alias_assert_or_deny(valence, extra_name)
39
+ Wrong::Assert.send(:alias_method, extra_name, valence)
40
+ new_method_name = extra_name.to_sym
41
+ self[:aliases][valence] << new_method_name unless self[:aliases][valence].include?(new_method_name)
42
+ end
43
+
36
44
  def alias_assert(method_name)
37
- Wrong::Assert.send(:alias_method, method_name, :assert)
38
- self.assert_method_names << method_name.to_sym unless self.assert_method_names.include?(method_name)
45
+ alias_assert_or_deny(:assert, method_name)
39
46
  end
40
47
 
41
48
  def alias_deny(method_name)
42
- Wrong::Assert.send(:alias_method, method_name, :deny)
43
- self.deny_method_names << method_name.to_sym unless self.deny_method_names.include?(method_name)
49
+ alias_assert_or_deny(:deny, method_name)
44
50
  end
45
51
 
46
52
  def assert_method_names
47
- (self[:assert_method] ||= [:assert])
53
+ self[:aliases][:assert]
48
54
  end
49
55
 
50
56
  def deny_method_names
51
- (self[:deny_method] ||= [:deny])
57
+ self[:aliases][:deny]
52
58
  end
53
59
 
54
60
  def assert_methods
data/lib/wrong/helpers.rb CHANGED
@@ -27,12 +27,7 @@ module Wrong
27
27
  streams.each do |stream|
28
28
  original[stream] = (stream == :stdout ? $stdout : $stderr)
29
29
  captured[stream] = StringIO.new
30
- case stream
31
- when :stdout
32
- $stdout = captured[stream]
33
- when :stderr
34
- $stderr = captured[stream]
35
- end
30
+ reassign_stream(stream, captured)
36
31
  end
37
32
 
38
33
  yield
@@ -53,14 +48,20 @@ module Wrong
53
48
  end
54
49
  # support nested calls to capturing
55
50
  original[stream] << captured[stream].string if original[stream].is_a? StringIO
56
- case stream
57
- when :stdout
58
- $stdout = original[stream]
59
- when :stderr
60
- $stderr = original[stream]
61
- end
51
+ reassign_stream(stream, original)
52
+ end
53
+ end
54
+
55
+ private
56
+ def reassign_stream(which, streams)
57
+ case which
58
+ when :stdout
59
+ $stdout = streams[which]
60
+ when :stderr
61
+ $stderr = streams[which]
62
62
  end
63
63
  end
64
+
64
65
  end
65
66
 
66
67
  end
data/lib/wrong/rainbow.rb CHANGED
@@ -27,18 +27,23 @@ module Sickill
27
27
  :hide => 8,
28
28
  }
29
29
 
30
+ private
31
+ def set_color(color, ground = :foreground)
32
+ color = color.first if color.size == 1
33
+ wrap_with_code(get_color_code(color, ground))
34
+ end
35
+
36
+ public
30
37
  # Sets foreground color of this text.
31
38
  def foreground(*color)
32
- color = color.first if color.size == 1
33
- wrap_with_code(get_color_code(color, :foreground))
39
+ set_color(color, :foreground)
34
40
  end
35
41
  alias_method :color, :foreground
36
42
  alias_method :colour, :foreground
37
43
 
38
44
  # Sets background color of this text.
39
45
  def background(*color)
40
- color = color.first if color.size == 1
41
- wrap_with_code(get_color_code(color, :background))
46
+ set_color(color, :background)
42
47
  end
43
48
 
44
49
  # Resets terminal to default colors/backgrounds.
data/lib/wrong/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wrong
2
- VERSION = "0.4.1" unless defined?(Wrong::VERSION)
2
+ VERSION = "0.4.2" unless defined?(Wrong::VERSION)
3
3
  end
data/test/config_test.rb CHANGED
@@ -54,6 +54,13 @@ alias_assert :yum
54
54
  end
55
55
  end
56
56
 
57
+ it "uses defaults if there is no .wrong file" do
58
+ Dir.chdir("/tmp") do # hopefull there's no .wrong file here or in /
59
+ config = Wrong.load_config
60
+ assert { config[:test_setting] == nil }
61
+ end
62
+ end
63
+
57
64
  end
58
65
 
59
66
  it "getting an undeclared setting" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 4
8
- - 1
9
- version: 0.4.1
8
+ - 2
9
+ version: 0.4.2
10
10
  platform: java
11
11
  authors:
12
12
  - Steve Conover
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-06 00:00:00 -07:00
18
+ date: 2010-10-08 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -163,7 +163,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
- hash: 2619962454554443825
166
+ hash: 2441793829226803943
167
167
  segments:
168
168
  - 0
169
169
  version: "0"