methodchain 0.4.0 → 0.4.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 +5 -10
- data/Rakefile +12 -94
- data/doc/created.rid +1 -1
- data/lib/methodchain.rb +2 -1
- data/tasks/gregproject.rake +59 -0
- data/tasks/helpers.rb +31 -0
- metadata +4 -1
data/README
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
== Summary
|
2
2
|
methodchain - ruby helpers for method chaining: chain, tap, then, else, and, or
|
3
|
+
===
|
3
4
|
Easy ways to navigate around nil without creating local variables.
|
5
|
+
===
|
6
|
+
<a href="http://blog.thoughtfolder.com/2008-03-16-navigating-nil-method-chaining-in-ruby.html#Object-chain">
|
7
|
+
Initial blog post describing previous ideas
|
8
|
+
</a>
|
4
9
|
|
5
10
|
== Author and License
|
6
11
|
Copyright (c) 2008 Greg Weber, http://gregweber.info
|
@@ -148,16 +153,6 @@ import will still load all the private methods from the module:
|
|
148
153
|
- send_as_functions
|
149
154
|
|
150
155
|
|
151
|
-
==== not into Object
|
152
|
-
To import nothing into the Object namespace
|
153
|
-
require 'methodchain/no-import'
|
154
|
-
|
155
|
-
Then include where needed:
|
156
|
-
class MyObject
|
157
|
-
include MethodChain
|
158
|
-
end
|
159
|
-
|
160
|
-
|
161
156
|
== Implementation
|
162
157
|
There are no proxy objects and no use of method_missing- these are simply function calls, so it should be fast.
|
163
158
|
|
data/Rakefile
CHANGED
@@ -1,95 +1,26 @@
|
|
1
|
-
project = "methodchain"
|
1
|
+
$project = "methodchain"
|
2
|
+
$rcov_index_html = 'coverage/lib-methodchain-not_included_rb.html'
|
2
3
|
|
3
|
-
|
4
|
-
puts msg
|
5
|
-
exit(code)
|
6
|
-
end
|
7
|
-
def run command
|
8
|
-
res = `#{command}`
|
9
|
-
exit_msg res, $?.exitstatus if $?.exitstatus != 0
|
10
|
-
res
|
11
|
-
end
|
12
|
-
def __DIR__; "#{File.dirname(__FILE__)}" end
|
4
|
+
require 'tasks/helpers'
|
13
5
|
|
14
|
-
def
|
15
|
-
Dir.mkdir 'tmp' unless File.directory? 'tmp'
|
16
|
-
Dir.chdir('tmp') do |dir|
|
17
|
-
yield dir
|
18
|
-
end
|
19
|
-
rm_rf 'tmp'
|
20
|
-
end
|
21
|
-
class IO
|
22
|
-
def self.write( file, str )
|
23
|
-
self.open( file, 'w' ) { |fh| fh.print str }
|
24
|
-
end
|
25
|
-
def self.read_write( file, write_file=file )
|
26
|
-
self.write(write_file, (yield( self.read( file ))))
|
27
|
-
end
|
28
|
-
end
|
6
|
+
def __DIR__; "#{File.dirname(__FILE__)}" end
|
29
7
|
|
30
8
|
desc "test run all tests"
|
31
9
|
task :test => [:spec, 'readme:test']
|
32
10
|
|
33
|
-
desc "run specs"
|
34
|
-
task :spec do
|
35
|
-
Dir[ 'spec/*' ].each do |file|
|
36
|
-
(puts (run "spec #{file}"))
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
require 'rubygems'
|
41
|
-
require 'spec/rake/spectask'
|
42
|
-
desc "verify test coverage with RCov"
|
43
|
-
task :rcov => 'rcov:verify'
|
44
|
-
namespace :rcov do
|
45
|
-
Spec::Rake::SpecTask.new('rcov') do |t|
|
46
|
-
t.spec_files = ['spec/*.rb']
|
47
|
-
t.rcov = true
|
48
|
-
t.rcov_opts = ['--exclude', 'spec']
|
49
|
-
end
|
50
|
-
|
51
|
-
require 'spec/rake/verify_rcov'
|
52
|
-
# rcov is wrong- I am actually at 100%
|
53
|
-
RCov::VerifyTask.new(:verify => :rcov) do |t|
|
54
|
-
t.threshold = 100 # Make sure you have rcov 0.7 or higher!
|
55
|
-
t.index_html = 'coverage/lib-methodchain-not_included_rb.html'
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
desc "release a new gem to rubyforge"
|
60
|
-
task :release => [:test,:record,:rdoc,:website,:package] do
|
61
|
-
Dir.chdir('pkg') do
|
62
|
-
release = Dir['*.gem'].sort_by {|file| File.mtime(file)}.last
|
63
|
-
release =~ /^[^-]+-([.0-9]+).gem$/
|
64
|
-
(puts (run "rubyforge login && rubyforge add_release #{project} #{project} #$1 #{release}"))
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
desc "update website"
|
69
|
-
file :website => ['README','Rakefile'] do
|
70
|
-
Dir.chdir '/home/greg/sites/projects/' do
|
71
|
-
(puts (run 'rake projects:update'))
|
72
|
-
(puts (run 'rake deploy:rsync'))
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
desc "generate documentation"
|
77
|
-
task :rdoc do
|
78
|
-
fail unless system 'rdoc --force-update --quiet README lib/*'
|
79
|
-
end
|
80
|
-
|
81
11
|
namespace :readme do
|
82
12
|
desc "create html for website using coderay, use --silent option"
|
83
13
|
task :html do
|
84
14
|
rm_rf 'doc'
|
85
15
|
`rdoc --quiet README`
|
86
16
|
require 'hpricot'
|
17
|
+
require 'htmlentities'
|
87
18
|
doc = open( 'doc/files/README.html' ) { |f| Hpricot(f) }
|
88
19
|
# find example code
|
89
20
|
doc.at('#description').search('pre').each do |ex|
|
90
21
|
#select {|elem| elem.inner_html =~ /class |module /}.each do |ex|
|
91
22
|
# add coderay and undo what rdoc has done in the example code
|
92
|
-
ex.swap("<coderay lang='ruby'>#{
|
23
|
+
ex.swap("<coderay lang='ruby'>#{HTMLEntities.new.decode ex.inner_html}</coderay>")
|
93
24
|
end
|
94
25
|
puts doc.at('#description').to_html
|
95
26
|
end
|
@@ -117,39 +48,26 @@ namespace :readme do
|
|
117
48
|
end
|
118
49
|
end
|
119
50
|
|
120
|
-
desc 'git add and push'
|
121
|
-
task :record do
|
122
|
-
unless `git diff`.chomp.empty?
|
123
|
-
ARGV.clear
|
124
|
-
puts "enter commit message"
|
125
|
-
(puts (run "git commit -a -m '#{Kernel.gets}'"))
|
126
|
-
puts "committed! now pushing.. "
|
127
|
-
(puts (run 'git push origin master'))
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
51
|
require 'rubygems'
|
132
52
|
require 'rake/gempackagetask'
|
133
53
|
|
134
54
|
spec = Gem::Specification.new do |s|
|
135
|
-
s.name = project
|
136
|
-
s.rubyforge_project = project
|
137
|
-
s.version = "0.4.
|
55
|
+
s.name = $project
|
56
|
+
s.rubyforge_project = $project
|
57
|
+
s.version = "0.4.1"
|
138
58
|
s.author = "Greg Weber"
|
139
59
|
s.email = "greg@gregweber.info"
|
140
|
-
s.homepage = "http://projects.gregweber.info/#{project}"
|
60
|
+
s.homepage = "http://projects.gregweber.info/#{$project}"
|
141
61
|
s.platform = Gem::Platform::RUBY
|
142
62
|
s.summary = "convenience methods for method chaining"
|
143
63
|
s.files =
|
144
64
|
FileList.new('./**', '*/**', 'lib/methodchain/*') do |fl|
|
145
|
-
|
146
|
-
|
147
|
-
p s.files
|
65
|
+
fl.exclude('pkg','pkg/*','tmp','tmp/*', 'coverage', 'coverage/*')
|
66
|
+
end
|
148
67
|
s.require_path = "lib"
|
149
68
|
s.has_rdoc = true
|
150
69
|
s.extra_rdoc_files = ["README"]
|
151
70
|
end
|
152
|
-
|
153
71
|
Rake::GemPackageTask.new(spec) do |pkg|
|
154
72
|
pkg.need_tar = false
|
155
73
|
end
|
data/doc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Mon, 24 Mar 2008
|
1
|
+
Mon, 24 Mar 2008 14:21:47 -0500
|
data/lib/methodchain.rb
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
desc "run specs"
|
2
|
+
task :spec do
|
3
|
+
Dir[ 'spec/*' ].each do |file|
|
4
|
+
out "spec #{file}"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'spec/rake/spectask'
|
10
|
+
desc "verify test coverage with RCov"
|
11
|
+
task :rcov => 'rcov:verify'
|
12
|
+
namespace :rcov do
|
13
|
+
Spec::Rake::SpecTask.new('rcov') do |t|
|
14
|
+
t.spec_files = ['spec/*.rb']
|
15
|
+
t.rcov = true
|
16
|
+
t.rcov_opts = ['--exclude', 'spec']
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'spec/rake/verify_rcov'
|
20
|
+
# rcov is wrong- I am actually at 100%
|
21
|
+
RCov::VerifyTask.new(:verify => :rcov) do |t|
|
22
|
+
t.threshold = 100 # Make sure you have rcov 0.7 or higher!
|
23
|
+
t.index_html = $rcov_index_html
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "release a new gem to rubyforge"
|
28
|
+
task :release => [:test,:record,:rdoc,:website,:package] do
|
29
|
+
Dir.chdir('pkg') do
|
30
|
+
release = Dir['*.gem'].sort_by {|file| File.mtime(file)}.last
|
31
|
+
release =~ /^[^-]+-([.0-9]+).gem$/
|
32
|
+
out "rubyforge login && rubyforge add_release #{$project} #{$project} #$1 #{release}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
desc "update website"
|
37
|
+
file :website => ['README','Rakefile'] do
|
38
|
+
Dir.chdir '/home/greg/sites/projects/' do
|
39
|
+
out 'rake --silent projects:update'
|
40
|
+
out 'rake --silent deploy:rsync'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc "generate documentation"
|
45
|
+
task :rdoc do
|
46
|
+
fail unless system 'rdoc --force-update --quiet README lib/*'
|
47
|
+
end
|
48
|
+
|
49
|
+
desc 'git add and push'
|
50
|
+
task :record do
|
51
|
+
unless `git diff`.chomp.empty?
|
52
|
+
ARGV.clear
|
53
|
+
puts "enter commit message"
|
54
|
+
out "git commit -a -m '#{Kernel.gets}'"
|
55
|
+
puts "committed! now pushing.. "
|
56
|
+
out 'git push origin master'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
data/tasks/helpers.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
def exit_msg(msg, code=1)
|
2
|
+
puts msg
|
3
|
+
exit(code)
|
4
|
+
end
|
5
|
+
def run command
|
6
|
+
res = `#{command}`
|
7
|
+
exit_msg res, $?.exitstatus if $?.exitstatus != 0
|
8
|
+
res
|
9
|
+
end
|
10
|
+
def out command
|
11
|
+
(puts (run command))
|
12
|
+
end
|
13
|
+
|
14
|
+
def cd_tmp
|
15
|
+
Dir.mkdir 'tmp' unless File.directory? 'tmp'
|
16
|
+
Dir.chdir('tmp') do |dir|
|
17
|
+
yield dir
|
18
|
+
end
|
19
|
+
rm_rf 'tmp'
|
20
|
+
end
|
21
|
+
|
22
|
+
class IO
|
23
|
+
def self.write( file, str )
|
24
|
+
self.open( file, 'w' ) { |fh| fh.print str }
|
25
|
+
end
|
26
|
+
def self.read_write( file, write_file=file )
|
27
|
+
self.write(write_file, (yield( self.read( file ))))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Dir.glob('tasks/*.rake').sort.each {|fn| import fn}
|
metadata
CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: methodchain
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.
|
6
|
+
version: 0.4.1
|
7
7
|
date: 2008-03-24 00:00:00 -05:00
|
8
8
|
summary: convenience methods for method chaining
|
9
9
|
require_paths:
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- ./lib
|
34
34
|
- ./spec
|
35
35
|
- ./Rakefile
|
36
|
+
- ./tasks
|
36
37
|
- ./README
|
37
38
|
- doc/files
|
38
39
|
- doc/index.html
|
@@ -45,6 +46,8 @@ files:
|
|
45
46
|
- lib/methodchain
|
46
47
|
- lib/methodchain.rb
|
47
48
|
- spec/methodchain_spec.rb
|
49
|
+
- tasks/helpers.rb
|
50
|
+
- tasks/gregproject.rake
|
48
51
|
- lib/methodchain/not-included.rb
|
49
52
|
- README
|
50
53
|
test_files: []
|