Permalink
Browse files

intial commit copying rubyforge

  • Loading branch information...
Reg Braithwaite
Reg Braithwaite committed Nov 1, 2008
0 parents commit 158c7b457acbcd09f1580bdb79e441bf8381430b
Showing with 8,596 additions and 0 deletions.
  1. +16 −0 History.txt
  2. +26 −0 License.txt
  3. +24 −0 Manifest.txt
  4. +136 −0 README.textile
  5. +4 −0 Rakefile
  6. +70 −0 config/hoe.rb
  7. +17 −0 config/requirements.rb
  8. +114 −0 doc/classes/AndAnd.html
  9. +152 −0 doc/classes/AndAnd/BlankSlate.html
  10. +18 −0 doc/classes/AndAnd/BlankSlate.src/M000007.html
  11. +18 −0 doc/classes/AndAnd/BlankSlate.src/M000008.html
  12. +163 −0 doc/classes/AndAnd/MockReturningMe.html
  13. +19 −0 doc/classes/AndAnd/MockReturningMe.src/M000005.html
  14. +18 −0 doc/classes/AndAnd/MockReturningMe.src/M000006.html
  15. +242 −0 doc/classes/AndAnd/ObjectGoodies.html
  16. +32 −0 doc/classes/AndAnd/ObjectGoodies.src/M000001.html
  17. +26 −0 doc/classes/AndAnd/ObjectGoodies.src/M000002.html
  18. +24 −0 doc/classes/AndAnd/ObjectGoodies.src/M000004.html
  19. +163 −0 doc/classes/AndAnd/ProxyReturningMe.html
  20. +19 −0 doc/classes/AndAnd/ProxyReturningMe.src/M000009.html
  21. +19 −0 doc/classes/AndAnd/ProxyReturningMe.src/M000010.html
  22. +120 −0 doc/classes/Object.html
  23. +1 −0 doc/created.rid
  24. +163 −0 doc/files/History_txt.html
  25. +134 −0 doc/files/License_txt.html
  26. +135 −0 doc/files/README_txt.html
  27. +101 −0 doc/files/lib/andand/version_rb.html
  28. +101 −0 doc/files/lib/andand_rb.html
  29. +374 −0 doc/files/website/index_txt.html
  30. +32 −0 doc/fr_class_index.html
  31. +32 −0 doc/fr_file_index.html
  32. +36 −0 doc/fr_method_index.html
  33. +24 −0 doc/index.html
  34. +208 −0 doc/rdoc-style.css
  35. +148 −0 lib/andand.rb
  36. +9 −0 lib/andand/version.rb
  37. 0 log/debug.log
  38. BIN pkg/andand-1.3.1.gem
  39. BIN pkg/andand-1.3.1.tgz
  40. +16 −0 pkg/andand-1.3.1/History.txt
  41. +26 −0 pkg/andand-1.3.1/License.txt
  42. +24 −0 pkg/andand-1.3.1/Manifest.txt
  43. +17 −0 pkg/andand-1.3.1/README.txt
  44. +4 −0 pkg/andand-1.3.1/Rakefile
  45. +70 −0 pkg/andand-1.3.1/config/hoe.rb
  46. +17 −0 pkg/andand-1.3.1/config/requirements.rb
  47. +148 −0 pkg/andand-1.3.1/lib/andand.rb
  48. +9 −0 pkg/andand-1.3.1/lib/andand/version.rb
  49. 0 pkg/andand-1.3.1/log/debug.log
  50. +14 −0 pkg/andand-1.3.1/script/destroy
  51. +14 −0 pkg/andand-1.3.1/script/generate
  52. +74 −0 pkg/andand-1.3.1/script/txt2html
  53. +1,585 −0 pkg/andand-1.3.1/setup.rb
  54. +34 −0 pkg/andand-1.3.1/tasks/deployment.rake
  55. +7 −0 pkg/andand-1.3.1/tasks/environment.rake
  56. +17 −0 pkg/andand-1.3.1/tasks/website.rake
  57. +11 −0 pkg/andand-1.3.1/test/test_andand.rb
  58. +2 −0 pkg/andand-1.3.1/test/test_helper.rb
  59. +230 −0 pkg/andand-1.3.1/website/index.html
  60. +136 −0 pkg/andand-1.3.1/website/index.txt
  61. +285 −0 pkg/andand-1.3.1/website/javascripts/rounded_corners_lite.inc.js
  62. +138 −0 pkg/andand-1.3.1/website/stylesheets/screen.css
  63. +50 −0 pkg/andand-1.3.1/website/template.rhtml
  64. +14 −0 script/destroy
  65. +14 −0 script/generate
  66. +74 −0 script/txt2html
  67. +1,585 −0 setup.rb
  68. +34 −0 tasks/deployment.rake
  69. +7 −0 tasks/environment.rake
  70. +17 −0 tasks/website.rake
  71. +133 −0 test/andand_spec.rb
  72. +11 −0 test/test_andand.rb
  73. +2 −0 test/test_helper.rb
  74. +230 −0 website/index.html
  75. +136 −0 website/index.txt
  76. +285 −0 website/javascripts/rounded_corners_lite.inc.js
  77. +138 −0 website/stylesheets/screen.css
  78. +50 −0 website/template.rhtml
@@ -0,0 +1,16 @@
+== 1.3.1 2008-07-12
+
+* 1 major enhancement:
+ * Initial release
+* 2 tiny enhancement:
+ * fixed specifications
+* 3 minor enhancement
+ * tap is now a synonym for me
+* 4 minor enhancement
+ * Object#dont
+* 5 bug fix
+ * Plays well with other patch-artists
+* 6 minor enhancement
+ * uses existing BlankSlate class if already defined
+* 7 tiny enhancement
+ * use BasicObject as well
@@ -0,0 +1,26 @@
+Copyright (c) 2008 Reginald Braithwaite
+http://weblog.raganwald.com/2008/01/objectandand-objectme-in-ruby.html
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Some code adapted from Jim Weirich's post:
+http://onestepback.org/index.cgi/Tech/Ruby/BlankSlate.rdoc
@@ -0,0 +1,24 @@
+History.txt
+License.txt
+Manifest.txt
+README.txt
+Rakefile
+config/hoe.rb
+config/requirements.rb
+lib/andand.rb
+lib/andand/version.rb
+log/debug.log
+script/destroy
+script/generate
+script/txt2html
+setup.rb
+tasks/deployment.rake
+tasks/environment.rake
+tasks/website.rake
+test/test_andand.rb
+test/test_helper.rb
+website/index.html
+website/index.txt
+website/javascripts/rounded_corners_lite.inc.js
+website/stylesheets/screen.css
+website/template.rhtml
@@ -0,0 +1,136 @@
+h1. Object#andand
+
+h1. → 'andand'
+
+h2. What
+
+_Object#andand_ lets us write:
+
+<pre syntax="ruby">
+@phone = Location.find(:first, ...elided... ).andand.phone
+</pre>And get a _guarded method invocation_ or _safe navigation method_. This snippet performs a @.find@ on the Location class, then sends @.phone@ to the result _if the result is not nil_. If the result is nil, then the expression returns nil without throwing a NoMethodError.
+
+As Dejan Simic "put it":http://rors.org/2008/3/18/andand:
+
+Why would you want to write this:
+
+<pre syntax="ruby">
+entry.at('description') && entry.at('description').inner_text
+</pre>when you can write this:
+
+<pre syntax="ruby">
+entry.at('description').andand.inner_text
+</pre>Why indeed! As a bonus, install andand and you will also receive an enhanced Object#tap method, _at no extra charge_!
+
+h2. Installing
+
+<pre syntax="ruby">sudo gem install andand</pre>
+
+h2. The basics
+
+h3. Object#andand
+
+Ruby programmers are familiar with the two _guarded assignment_ operators @&&=@ and @||=@. The typical use for them is when you have a variable that might be nil. For example:
+
+<pre syntax="ruby">
+first_name &&= @first_name.trim
+@phone ||= '612-777-9311'
+</pre>You are trimming the first name provided it isn’t nil, and you are assigning ‘612-777-9311’ to the phone if it _is_ nil (or false, but that isn’t important right now). The other day we were discussing the guards and we agreed that we wished there was a _guarded method invocation_ operator. Here’s an example of when you would use it:
+
+<pre syntax="ruby">
+@phone = Location.find(:first, ...elided... )&&.phone
+</pre>Meaning, search the location table for the first record matching some criteria, and if you find a location, get its phone. If you don’t, get nil. (Groovy provides this exact functionality, although Groovy uses @?.@ instead of @&&.@) However, @&&.@ won’t work because @&&.@ is not a real Ruby operator.
+
+Object#andand let&rsquo;s us write:
+
+<pre syntax="ruby">
+@phone = Location.find(:first, ...elided... ).andand.phone
+</pre>And get the same effect as:
+
+<pre syntax="ruby">
+@phone = ->(loc){ loc && loc.phone }.call(Location.find(:first, ...elided... ))
+</pre>Note that because you accept any method using Ruby’s method invocation syntax, you can accept methods with parameters and/or blocks:
+
+<pre syntax="ruby">
+list_of_lists.detect { ...elided... }.andand.inject(42) { ...elided ... }
+</pre>Object#andand emphasizes syntactic regularity: the goal was to make an @&&.@ operation that worked like @&&=@. @&&=@ looks just like normal assignment, you can use any expression on the RHS, only the semantics are different. The andand method also works just like a normal method invocation, only the semantics are modified.
+
+h3. Use andand to simplify your regular expression matching and extraction
+
+Do you ever find yourself wanting to extract a single value from a string using a regular expression? For example, Ruby's Tempfile class creates paths to files that end in .pid.n (where pid is your process id and n is some number). Do you have a path that might be a tempfile and you want to obtain the base name?
+
+Do you currently retrieve the MatchData object, check if it is nil, and get the first matching group if it isn't? How about:
+
+<pre syntax="ruby">
+require 'tempfile'
+path = Tempfile.new('foo.bar').path
+ => "/var/folders/UZ/UZyZsbVPEWqC7tTXrQBYGU+++TI/-Tmp-/foo.bar.1280.0"
+path.match('/([^/]+)\.[0-9]+\.[0-9]+$').andand[1]
+ => "foo.bar"
+</pre>With @.andand[1]@, you extract the group in the regular expression safely: if the expression matches, you get the group. If the expression fails to match, you get nil. Which is what you want, isn't it? The contents of the group if the expression matches? Why should you need more than one line for something so simple?
+
+h3. Enhanced Object#tap
+
+Ruby 1.9 introduces "Object#tap":http://moonbase.rydia.net/mental/blog/programming/eavesdropping-on-expressions. This library implements Object#tap for Ruby 1.8 *and* enhances it. As in Ruby 1.9, you can call @.tap@ with a block:
+
+<pre syntax="ruby">
+ blah.sort.grep( /foo/ ).tap { |xs| p xs }.map { |x| x.blah }
+</pre> But like its sibling @.andand@, you can now call @.tap@ with a method as well:
+
+<pre syntax="ruby">
+ [1, 2, 3, 4, 5].tap.pop.map { |n| n * 2 }
+ => [2, 4, 6, 8]
+</pre>
+
+h3. Doctor, it hurts when I do that
+
+_So don't do that!_
+
+The popular use case for Object#tap is poor man's debugging:
+
+<pre syntax="ruby">
+ blah.sort.grep( /foo/ ).tap { |xs| p xs }.map { |x| x.blah }
+</pre>Perhaps you want to remove the tap, you can delete it:
+
+<pre syntax="ruby">
+ blah.sort.grep( /foo/ ).map { |x| x.blah }
+</pre>Or, you can change it to @.dont@:
+
+<pre syntax="ruby">
+ blah.sort.grep( /foo/ ).dont { |xs| p xs }.map { |x| x.blah }
+</pre>Like @.andand@ and @.tap@, @.dont@ works with arbitrary methods, not just blocks:
+
+<pre syntax="ruby">
+ (1..10).to_a.reverse!
+ => [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
+ (1..10).to_a.dont.reverse!
+ => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+</pre>
+
+h2. A little more background
+
+"Object#andand & Object#me in Ruby":http://weblog.raganwald.com/2008/01/objectandand-objectme-in-ruby.html explains the original motivations, as well as providing links to similar implementations you may want to consider. A few people have pointed out that Object#andand is similar to Haskell's Maybe monad. "The Maybe Monad in Ruby":http://blog.pretheory.com/arch/2008/02/the_maybe_monad_in_ruby.php is a good introduction for Ruby programmers.
+
+h2. That's cool, but&hellip;
+
+No problem, I get that andand isn't exactly what you need. Have a look at the "Invocation Construction Kit":http://ick.rubyforge.org or "Ick." The Ick gem _generalizes_ #andand and #tap: Ick provides four useful ways to block-structure your code, the methods #let, #returning, #inside, and #my. Ick also includes four quasi-monadic invocations, #maybe, #please, #tee, and #fork.
+
+"Ick":http://ick.rubyforge.org provides abstractions for building your own invocations, so you can branch out and build some of your own abstractions with Ick's building blocks.
+
+h2. How to submit patches
+
+Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/.
+
+The trunk repository is @svn://rubyforge.org/var/svn/andand/trunk@ for anonymous access.
+
+h2. License
+
+This code is free to use under the terms of the "MIT license":http://en.wikipedia.org/wiki/MIT_License.
+
+h2. Shout Out
+
+"Mobile Commons":http://mcommons.com/. Huge.
+
+h2. Contact
+
+Comments are welcome. Send an email to "Reginald Braithwaite":mailto:raganwald+rubyforge@gmail.com.
@@ -0,0 +1,4 @@
+require 'config/requirements'
+require 'config/hoe' # setup Hoe + all gem configuration
+
+Dir['tasks/**/*.rake'].each { |rake| load rake }
@@ -0,0 +1,70 @@
+require 'andand/version'
+
+AUTHOR = 'Reginald Braithwaite' # can also be an array of Authors
+EMAIL = "reg@braythwayt.com"
+DESCRIPTION = "adds guarded method invocation to Ruby"
+GEM_NAME = 'andand' # what ppl will type to install your gem
+RUBYFORGE_PROJECT = 'andand' # The unix name for your project
+HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
+DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
+
+@config_file = "~/.rubyforge/user-config.yml"
+@config = nil
+RUBYFORGE_USERNAME = "raganwald"
+def rubyforge_username
+ unless @config
+ begin
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
+ rescue
+ puts <<-EOS
+ERROR: No rubyforge config file found: #{@config_file}
+Run 'rubyforge setup' to prepare your env for access to Rubyforge
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
+ EOS
+ exit
+ end
+ end
+ RUBYFORGE_USERNAME.replace @config["username"]
+end
+
+
+REV = nil
+# UNCOMMENT IF REQUIRED:
+# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
+VERS = Andand::VERSION::STRING + (REV ? ".#{REV}" : "")
+RDOC_OPTS = ['--quiet', '--title', 'andand documentation',
+ "--opname", "index.html",
+ "--line-numbers",
+ "--main", "README",
+ "--inline-source"]
+
+class Hoe
+ def extra_deps
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
+ @extra_deps
+ end
+end
+
+# Generate all the Rake tasks
+# Run 'rake -T' to see list of generated tasks (from gem root directory)
+hoe = Hoe.new(GEM_NAME, VERS) do |p|
+ p.developer(AUTHOR, EMAIL)
+ p.description = DESCRIPTION
+ p.summary = DESCRIPTION
+ p.url = HOMEPATH
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
+ p.test_globs = ["test/**/test_*.rb"]
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
+
+ # == Optional
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
+
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
+
+end
+
+CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
+PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
+hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
+hoe.rsync_args = '-av --delete --ignore-errors'
@@ -0,0 +1,17 @@
+require 'fileutils'
+include FileUtils
+
+require 'rubygems'
+%w[rake hoe newgem rubigen].each do |req_gem|
+ begin
+ require req_gem
+ rescue LoadError
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
+ puts "Installation: gem install #{req_gem} -y"
+ exit
+ end
+end
+
+$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
+
+require 'andand'
Oops, something went wrong.

0 comments on commit 158c7b4

Please sign in to comment.