secret_sauce 0.0.1.pre → 0.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/README.md +4 -2
- data/lib/secret_sauce/core_ext/enumerable.rb +18 -0
- data/lib/secret_sauce/core_ext/string.rb +21 -0
- data/lib/secret_sauce/version.rb +1 -1
- data/secret_sauce.gemspec +2 -3
- data/spec/secret_sauce/core_ext/enumerable_spec.rb +39 -0
- data/spec/secret_sauce/core_ext/string_spec.rb +55 -0
- data/spec/spec_helper.rb +8 -0
- metadata +14 -25
- data/spec/core_ext/enumerable_spec.rb +0 -10
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Secret Sauce
|
1
|
+
# Secret Sauce [](http://travis-ci.org/gbchaosmaster/secret_sauce)
|
2
2
|
|
3
3
|
This library is my personal collection of Ruby utilities, mainly core
|
4
4
|
extensions.
|
@@ -7,7 +7,9 @@ extensions.
|
|
7
7
|
|
8
8
|
Install with RubyGems:
|
9
9
|
|
10
|
-
|
10
|
+
```Shell
|
11
|
+
gem install secret_sauce
|
12
|
+
```
|
11
13
|
|
12
14
|
## License
|
13
15
|
|
@@ -1,3 +1,21 @@
|
|
1
1
|
module Enumerable
|
2
2
|
alias_method :contains?, :include?
|
3
|
+
alias_method :includes?, :include?
|
4
|
+
|
5
|
+
# The inverse of <tt>Enumerable#include?</tt>. Returns +true+ if the
|
6
|
+
# collection does not contain +object+.
|
7
|
+
def exclude? object
|
8
|
+
!include? object
|
9
|
+
end
|
10
|
+
alias_method :excludes?, :exclude?
|
11
|
+
|
12
|
+
# Returns the sum of all numeric elements in the collection
|
13
|
+
#
|
14
|
+
# [1, 2, 3].sum # => 6
|
15
|
+
# [[1, 2], [3, 4]].sum # => 10
|
16
|
+
# { a: 4, b: 5 }.sum # => 9
|
17
|
+
# [2, "string", 9].sum # => 11
|
18
|
+
def sum
|
19
|
+
flatten.select { |e| e.is_a? Numeric }.inject(:+) || 0
|
20
|
+
end
|
3
21
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class String
|
2
|
+
alias_method :contains?, :include?
|
3
|
+
alias_method :includes?, :include?
|
4
|
+
|
5
|
+
alias_method :each, :each_char
|
6
|
+
|
7
|
+
# The inverse of <tt>String#include?</tt>. Returns +true+ if the string does
|
8
|
+
# not contain +str+.
|
9
|
+
def exclude? str
|
10
|
+
!include? str
|
11
|
+
end
|
12
|
+
alias_method :excludes?, :exclude?
|
13
|
+
|
14
|
+
# Left-aligns a heredoc by finding the lest indented line in the string, and
|
15
|
+
# removing that amount of leading whitespace.
|
16
|
+
def heredoc
|
17
|
+
gsub /^[ \t]{#{scan(/^[ \t]*(?=\S)/).min.size}}/, ""
|
18
|
+
end
|
19
|
+
alias_method :format_heredoc, :heredoc
|
20
|
+
alias_method :strip_heredoc, :heredoc
|
21
|
+
end
|
data/lib/secret_sauce/version.rb
CHANGED
data/secret_sauce.gemspec
CHANGED
@@ -11,8 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.license = "MIT"
|
12
12
|
|
13
13
|
gem.summary = "Library to boost Ruby's functionality."
|
14
|
-
|
15
|
-
gem.description = gem.summary
|
14
|
+
gem.description = "My collection of Ruby utilities, mainly core extensions."
|
16
15
|
|
17
16
|
gem.require_paths = %w[lib]
|
18
17
|
gem.test_files = Dir["spec/**/*"]
|
@@ -20,7 +19,7 @@ Gem::Specification.new do |gem|
|
|
20
19
|
LICENSE Rakefile README.md secret_sauce.gemspec
|
21
20
|
]
|
22
21
|
|
23
|
-
gem.
|
22
|
+
gem.required_ruby_version = ">= 1.9.2"
|
24
23
|
gem.add_development_dependency "rake"
|
25
24
|
gem.add_development_dependency "rspec"
|
26
25
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "secret_sauce/core_ext/enumerable"
|
3
|
+
|
4
|
+
describe Enumerable do
|
5
|
+
describe "aliases" do
|
6
|
+
test_alias Enumerable, :contains?, :include?
|
7
|
+
test_alias Enumerable, :includes?, :include?
|
8
|
+
test_alias Enumerable, :excludes?, :exclude?
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#exclude?" do
|
12
|
+
it "should return true if the collection does not contain the input" do
|
13
|
+
[1, 2, 3].exclude?(4).should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return false if the collection contains the input" do
|
17
|
+
[1, 2, 3].exclude?(2).should be_false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#sum" do
|
22
|
+
it "should return the sum of elements" do
|
23
|
+
[].sum.should == 0
|
24
|
+
[5].sum.should == 5
|
25
|
+
[1, 2, 3].sum.should == 6
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should flatten the elements before adding" do
|
29
|
+
[[4, 5], 1].sum.should == 10
|
30
|
+
[[1, 2, 3], [4, 5]].sum.should == 15
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should filter out all non-numbers" do
|
34
|
+
{ a: 2, b: 4 }.sum.should == 6
|
35
|
+
[1, "str", 4].sum.should == 5
|
36
|
+
["no numbers"].sum.should == 0
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "secret_sauce/core_ext/string"
|
3
|
+
|
4
|
+
describe Enumerable do
|
5
|
+
describe "aliases" do
|
6
|
+
test_alias String, :contains?, :include?
|
7
|
+
test_alias String, :includes?, :include?
|
8
|
+
test_alias String, :excludes?, :exclude?
|
9
|
+
|
10
|
+
test_alias String, :each, :each_char
|
11
|
+
|
12
|
+
test_alias String, :format_heredoc, :heredoc
|
13
|
+
test_alias String, :strip_heredoc, :heredoc
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#exclude?" do
|
17
|
+
it "should return true if the string does not contain the input string" do
|
18
|
+
"hello".exclude?("test").should be_true
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return false if the string contains the input string" do
|
22
|
+
"hello".exclude?("llo").should be_false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "#heredoc" do
|
27
|
+
test = expected = ""
|
28
|
+
|
29
|
+
before do
|
30
|
+
test = <<-EOS.heredoc
|
31
|
+
This is a test of String#heredoc.
|
32
|
+
This text should be left-aligned.
|
33
|
+
This text is indented by four spaces.
|
34
|
+
now three spaces...
|
35
|
+
now two spaces...
|
36
|
+
now one space...
|
37
|
+
Left-aligned again.
|
38
|
+
EOS
|
39
|
+
|
40
|
+
expected = <<EOS
|
41
|
+
This is a test of String#heredoc.
|
42
|
+
This text should be left-aligned.
|
43
|
+
This text is indented by four spaces.
|
44
|
+
now three spaces...
|
45
|
+
now two spaces...
|
46
|
+
now one space...
|
47
|
+
Left-aligned again.
|
48
|
+
EOS
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should strip all excess whitespace from the left" do
|
52
|
+
test.should == expected
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Tests if +method_a+ is an alias to +method_b+ in the class +cls+.
|
2
|
+
def test_alias(cls, method_a, method_b)
|
3
|
+
describe "##{method_a.to_s}" do
|
4
|
+
it "should be an alias of ##{method_b.to_s}" do
|
5
|
+
cls.instance_method(method_a).should === cls.instance_method(method_b)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
metadata
CHANGED
@@ -1,32 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: secret_sauce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Vinny Diehl
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: bundler
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
14
|
- !ruby/object:Gem::Dependency
|
31
15
|
name: rake
|
32
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,17 +43,20 @@ dependencies:
|
|
59
43
|
- - ! '>='
|
60
44
|
- !ruby/object:Gem::Version
|
61
45
|
version: '0'
|
62
|
-
description:
|
46
|
+
description: My collection of Ruby utilities, mainly core extensions.
|
63
47
|
email: gbchaosmaster926@gmail.com
|
64
48
|
executables: []
|
65
49
|
extensions: []
|
66
50
|
extra_rdoc_files: []
|
67
51
|
files:
|
68
52
|
- lib/secret_sauce/version.rb
|
53
|
+
- lib/secret_sauce/core_ext/string.rb
|
69
54
|
- lib/secret_sauce/core_ext/enumerable.rb
|
70
55
|
- lib/secret_sauce/core_ext.rb
|
71
56
|
- lib/secret_sauce.rb
|
72
|
-
- spec/core_ext/enumerable_spec.rb
|
57
|
+
- spec/secret_sauce/core_ext/enumerable_spec.rb
|
58
|
+
- spec/secret_sauce/core_ext/string_spec.rb
|
59
|
+
- spec/spec_helper.rb
|
73
60
|
- LICENSE
|
74
61
|
- Rakefile
|
75
62
|
- README.md
|
@@ -86,13 +73,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
73
|
requirements:
|
87
74
|
- - ! '>='
|
88
75
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
76
|
+
version: 1.9.2
|
90
77
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
78
|
none: false
|
92
79
|
requirements:
|
93
|
-
- - ! '
|
80
|
+
- - ! '>='
|
94
81
|
- !ruby/object:Gem::Version
|
95
|
-
version:
|
82
|
+
version: '0'
|
96
83
|
requirements: []
|
97
84
|
rubyforge_project:
|
98
85
|
rubygems_version: 1.8.24
|
@@ -100,4 +87,6 @@ signing_key:
|
|
100
87
|
specification_version: 3
|
101
88
|
summary: Library to boost Ruby's functionality.
|
102
89
|
test_files:
|
103
|
-
- spec/core_ext/enumerable_spec.rb
|
90
|
+
- spec/secret_sauce/core_ext/enumerable_spec.rb
|
91
|
+
- spec/secret_sauce/core_ext/string_spec.rb
|
92
|
+
- spec/spec_helper.rb
|