guerrilla_patch 2.0.0 → 2.1.0
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 +32 -3
- data/VERSION +1 -1
- data/guerrilla_patch.gemspec +3 -2
- data/lib/guerrilla_patch/kernel.rb +30 -0
- data/spec/guerrilla_patch/kernel_spec.rb +45 -0
- metadata +12 -11
data/README.md
CHANGED
@@ -3,9 +3,9 @@ Guerrilla Patch
|
|
3
3
|
|
4
4
|
I am tired of hunting and tracking down my own monkey patches. Not to mention hassle of dragging them between projects. I figured gem is a remedy for this.
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
Support for defining one liners with more succinct syntax (let,
|
6
|
+
Short onliners method definition
|
7
|
+
--------------------------------
|
8
|
+
Support for defining one liners with more succinct syntax (let, let_self)
|
9
9
|
|
10
10
|
```
|
11
11
|
def right?
|
@@ -23,7 +23,36 @@ Becomes beautiful
|
|
23
23
|
|
24
24
|
```
|
25
25
|
let(:right?) { @right ? "YES" : "NO" }
|
26
|
+
```
|
27
|
+
|
28
|
+
The only sweet spot for this that I could find are really simple and short methods.
|
29
|
+
|
30
|
+
Complex string expressions concatenation
|
31
|
+
-----------------------------------------
|
32
|
+
|
33
|
+
Support for combining complex string expressions (not for the performance, but for the looks)
|
34
|
+
|
35
|
+
```
|
36
|
+
def mark
|
37
|
+
year_of_manufacure <<
|
38
|
+
city.blank? '' : city.address <<
|
39
|
+
person.blank? '' : person.name[2..4]
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
You can write like this
|
44
|
+
|
45
|
+
```
|
46
|
+
def mark
|
47
|
+
consists_of do |r|
|
48
|
+
r.add year_of_manufacure
|
49
|
+
r.when_present(city) { |c| c.address }
|
50
|
+
r.when_present(person) { |p| p.name[2..4] }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
```
|
26
54
|
|
55
|
+
Somehow for my convoluted brain the later reads better.
|
27
56
|
|
28
57
|
Contributing to guerrilla_patch
|
29
58
|
-------------------------------
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.1.0
|
data/guerrilla_patch.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "guerrilla_patch"
|
8
|
-
s.version = "2.
|
8
|
+
s.version = "2.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["drKreso"]
|
12
|
-
s.date = "2012-01
|
12
|
+
s.date = "2012-03-01"
|
13
13
|
s.description = "I am tierd of hunting down monkey patches at large. Caging them inside this gem"
|
14
14
|
s.email = "kresimir.bojcic@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
|
|
29
29
|
"lib/guerrilla_patch.rb",
|
30
30
|
"lib/guerrilla_patch/kernel.rb",
|
31
31
|
"lib/guerrilla_patch/string.rb",
|
32
|
+
"spec/guerrilla_patch/kernel_spec.rb",
|
32
33
|
"spec/guerrilla_patch/string_spec.rb"
|
33
34
|
]
|
34
35
|
s.homepage = "http://github.com/drkreso/guerrilla_patch"
|
@@ -6,4 +6,34 @@ module Kernel
|
|
6
6
|
def let_self(name, &block)
|
7
7
|
define_singleton_method(name, &block)
|
8
8
|
end
|
9
|
+
|
10
|
+
def when_present(item, &block)
|
11
|
+
if block_given?
|
12
|
+
item.nil? ? '' : block.call(item)
|
13
|
+
else
|
14
|
+
item
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def consists_of
|
19
|
+
PoorsManStringBuilder.new.tap { |builder| yield(builder) }.result
|
20
|
+
end
|
21
|
+
|
22
|
+
class PoorsManStringBuilder
|
23
|
+
attr_reader :result
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@result = ''
|
27
|
+
end
|
28
|
+
|
29
|
+
def add(item)
|
30
|
+
@result << item.to_s
|
31
|
+
end
|
32
|
+
alias :always :add
|
33
|
+
|
34
|
+
def when_present(item, &block)
|
35
|
+
@result << Kernel.when_present(item, &block).to_s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
9
39
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'guerrilla_patch/kernel.rb'
|
2
|
+
|
3
|
+
describe Kernel do
|
4
|
+
|
5
|
+
it 'wraps commnon nil object idiom' do
|
6
|
+
test_object = nil
|
7
|
+
when_present(test_object) { |t| t }.should == ''
|
8
|
+
test_object = 'I am here'
|
9
|
+
when_present(test_object) { |t| t }.should == 'I am here'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'takes the block result and concatenates' do
|
13
|
+
test_object = 'I am here'
|
14
|
+
when_present(test_object) { |t| t * 2 }.should == 'I am hereI am here'
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'behaves graceafully when no block is given' do
|
18
|
+
test_object = "miki"
|
19
|
+
when_present(test_object).should == test_object
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'concatenates result to one string' do
|
23
|
+
consists_of do |r|
|
24
|
+
r.add "AAAAAA"
|
25
|
+
r.add "BBBBBB"
|
26
|
+
end.should == "AAAAAABBBBBB"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'concatenates result to one string taking care of nil objects' do
|
30
|
+
test_object = nil
|
31
|
+
consists_of do |r|
|
32
|
+
r.always "AAAAAA"
|
33
|
+
r.always "BBBBBB"
|
34
|
+
r.when_present(test_object) { |to| to << "BABY"}
|
35
|
+
end.should == "AAAAAABBBBBB"
|
36
|
+
|
37
|
+
test_object = 'YEAH'
|
38
|
+
consists_of do |r|
|
39
|
+
r.add "AAAAAA"
|
40
|
+
r.add "BBBBBB"
|
41
|
+
r.when_present(test_object) { |to| to << "BABY"}
|
42
|
+
end.should == "AAAAAABBBBBBYEAHBABY"
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guerrilla_patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
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-01
|
12
|
+
date: 2012-03-01 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70351104552780 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.8.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70351104552780
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: bundler
|
27
|
-
requirement: &
|
27
|
+
requirement: &70351104552300 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70351104552300
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: jeweler
|
38
|
-
requirement: &
|
38
|
+
requirement: &70351104551820 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.6.4
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70351104551820
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rcov
|
49
|
-
requirement: &
|
49
|
+
requirement: &70351104551340 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70351104551340
|
58
58
|
description: I am tierd of hunting down monkey patches at large. Caging them inside
|
59
59
|
this gem
|
60
60
|
email: kresimir.bojcic@gmail.com
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- lib/guerrilla_patch.rb
|
77
77
|
- lib/guerrilla_patch/kernel.rb
|
78
78
|
- lib/guerrilla_patch/string.rb
|
79
|
+
- spec/guerrilla_patch/kernel_spec.rb
|
79
80
|
- spec/guerrilla_patch/string_spec.rb
|
80
81
|
homepage: http://github.com/drkreso/guerrilla_patch
|
81
82
|
licenses:
|
@@ -92,7 +93,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
93
|
version: '0'
|
93
94
|
segments:
|
94
95
|
- 0
|
95
|
-
hash:
|
96
|
+
hash: 4392011064532060318
|
96
97
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
98
|
none: false
|
98
99
|
requirements:
|