iron-extensions 1.0.0 → 1.0.1
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.
- data/History.txt +8 -0
- data/README.rdoc +5 -5
- data/Version.txt +1 -0
- data/lib/iron/extensions.rb +2 -2
- data/lib/iron/extensions/kernel.rb +7 -2
- data/lib/iron/extensions/string.rb +3 -2
- data/spec/extensions/kernel_spec.rb +22 -0
- data/spec/extensions/numeric_spec.rb +25 -0
- data/spec/extensions/object_spec.rb +0 -1
- data/spec/extensions/symbol_spec.rb +12 -0
- metadata +9 -7
- data/sample.rdoc +0 -3
- data/version.txt +0 -1
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 1.0.1 / 2012-03-03
|
2
|
+
|
3
|
+
* Updated docs, fixed up minor packaging issues
|
4
|
+
* Added spec coverage for Kernel extensions
|
5
|
+
* Added spec coverage for Numeric extensions
|
6
|
+
* Added spec coverage for Symbol extensions
|
7
|
+
* Commit to GitHub, update gem homepage to reflect same
|
8
|
+
|
1
9
|
== 1.0.0 / 2012-03-02
|
2
10
|
|
3
11
|
* Broke out extensions from older irongaze gem
|
data/README.rdoc
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Written by Rob Morris @ Irongaze Consulting LLC (http://irongaze.com)
|
4
4
|
|
5
|
-
== DESCRIPTION
|
5
|
+
== DESCRIPTION
|
6
6
|
|
7
7
|
Helpful extensions to core Ruby classes
|
8
8
|
|
9
|
-
== ADDED EXTENSIONS
|
9
|
+
== ADDED EXTENSIONS
|
10
10
|
|
11
11
|
* Array#rand / Array#rand! - pull n random items from the array
|
12
12
|
|
@@ -84,17 +84,17 @@ Helpful extensions to core Ruby classes
|
|
84
84
|
* Symbol#blank? - always false
|
85
85
|
* Symbol#to_dashcase - same as for String
|
86
86
|
|
87
|
-
== SYNOPSIS
|
87
|
+
== SYNOPSIS
|
88
88
|
|
89
89
|
To use:
|
90
90
|
|
91
91
|
require 'iron/extensions'
|
92
92
|
|
93
|
-
== REQUIREMENTS
|
93
|
+
== REQUIREMENTS
|
94
94
|
|
95
95
|
* None
|
96
96
|
|
97
|
-
== INSTALL
|
97
|
+
== INSTALL
|
98
98
|
|
99
99
|
To install, simply run:
|
100
100
|
|
data/Version.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.1
|
data/lib/iron/extensions.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# Requires all
|
2
|
-
search_path = File.join(File.expand_path(File.dirname(__FILE__)), '
|
1
|
+
# Requires all classes
|
2
|
+
search_path = File.join(File.expand_path(File.dirname(__FILE__)), '*', '*.rb')
|
3
3
|
Dir.glob(search_path) do |path|
|
4
4
|
require path
|
5
5
|
end
|
@@ -1,9 +1,14 @@
|
|
1
|
-
|
2
1
|
require 'stringio'
|
3
2
|
|
4
3
|
module Kernel
|
5
4
|
|
6
|
-
|
5
|
+
# Captures STDOUT content and returns it as a string
|
6
|
+
#
|
7
|
+
# >> capture_stdout do
|
8
|
+
# >> puts 'Heya'
|
9
|
+
# >> end
|
10
|
+
# => "Heya\n"
|
11
|
+
def capture_stdout # :yields:
|
7
12
|
out = StringIO.new
|
8
13
|
$stdout = out
|
9
14
|
yield
|
@@ -77,7 +77,8 @@ class String
|
|
77
77
|
s = self.dup
|
78
78
|
s.gsub!(/\'/,'') # remove ' from rob's, so we don't get rob_s_blog
|
79
79
|
s.gsub!(/\W+/, ' ') # all non-word chars to spaces
|
80
|
-
s.
|
80
|
+
s.gsub!('_',' ') # we don't like underscores
|
81
|
+
s.strip! # ooh la la
|
81
82
|
s.downcase! #
|
82
83
|
s.gsub!(/\ +/, '-') # spaces to dashes, preferred separator char everywhere
|
83
84
|
s
|
@@ -152,7 +153,7 @@ class String
|
|
152
153
|
|
153
154
|
# In case we're running in Rails, which defines this already...
|
154
155
|
unless ''.respond_to?(:constantize)
|
155
|
-
def constantize
|
156
|
+
def constantize
|
156
157
|
names = self.split('::')
|
157
158
|
names.shift if names.empty? || names.first.empty?
|
158
159
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
describe Kernel do
|
2
|
+
|
3
|
+
it 'should capture STDOUT text' do
|
4
|
+
capture_stdout do
|
5
|
+
puts "hello\nworld!"
|
6
|
+
end.should == "hello\nworld!\n"
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'should restore STDOUT correctly on exceptions' do
|
10
|
+
old = $stdout
|
11
|
+
old.should == STDOUT
|
12
|
+
begin
|
13
|
+
capture_stdout do
|
14
|
+
raise 'foo'
|
15
|
+
end
|
16
|
+
rescue
|
17
|
+
end
|
18
|
+
$stdout.should == STDOUT
|
19
|
+
$stdout.should == old
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
describe Numeric do
|
2
|
+
|
3
|
+
it 'should display correctly no matter the base type' do
|
4
|
+
100.to_display(2).should == '100'
|
5
|
+
100.0.to_display(2).should == '100.00'
|
6
|
+
12345.to_display.should == '12,345'
|
7
|
+
123450000066666234234.should be_an_instance_of(Bignum)
|
8
|
+
123450000066666234234.to_display.should == '123,450,000,066,666,234,234'
|
9
|
+
0.0004.to_display
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should display correctly when negative' do
|
13
|
+
-5.to_display.should == '-5'
|
14
|
+
-42333.194.to_display(1).should == '-42,333.1'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should bound itself' do
|
18
|
+
1.bound(2,5).should == 2
|
19
|
+
5.bound(2,5).should == 5
|
20
|
+
2.bound(2,5).should == 2
|
21
|
+
-1000.bound(-5,5).should == -5
|
22
|
+
555.bound(-1,0).should == 0
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iron-extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-03 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2156310200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '2.6'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2156310200
|
25
25
|
description: Adds common extensions to core Ruby classes
|
26
26
|
email:
|
27
27
|
- rob@irongaze.com
|
@@ -44,16 +44,18 @@ files:
|
|
44
44
|
- lib/iron/extensions/symbol.rb
|
45
45
|
- lib/iron/extensions.rb
|
46
46
|
- spec/extensions/enumerable_spec.rb
|
47
|
+
- spec/extensions/kernel_spec.rb
|
48
|
+
- spec/extensions/numeric_spec.rb
|
47
49
|
- spec/extensions/object_spec.rb
|
48
50
|
- spec/extensions/string_spec.rb
|
51
|
+
- spec/extensions/symbol_spec.rb
|
49
52
|
- spec/spec_helper.rb
|
50
53
|
- LICENSE
|
51
54
|
- History.txt
|
52
|
-
-
|
55
|
+
- Version.txt
|
53
56
|
- README.rdoc
|
54
|
-
- sample.rdoc
|
55
57
|
- .rspec
|
56
|
-
homepage:
|
58
|
+
homepage: https://github.com/irongaze/iron-extensions
|
57
59
|
licenses:
|
58
60
|
- MIT
|
59
61
|
post_install_message:
|
data/sample.rdoc
DELETED
data/version.txt
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
1.0.0
|