Permalink
Browse files

Initial commit of "its-it" transformation: Renamed, incorporated jewe…

…ler, tidied up.
  • Loading branch information...
1 parent 4760957 commit 735776a29d328821c1097575eec0b7e9cd59832b @ronen committed Apr 23, 2011
View
5 .document
@@ -0,0 +1,5 @@
+lib/**/*.rb
+bin/*
+-
+features/**/*.feature
+LICENSE.txt
View
18 .gitignore
@@ -0,0 +1,18 @@
+# rcov generated
+coverage
+
+# rdoc generated
+rdoc
+
+# yard generated
+doc
+.yardoc
+
+# bundler
+.bundle
+
+# jeweler generated
+pkg
+
+# don't commit Gitfile.lock for gems
+Gitfile.lock
View
1 .rspec
@@ -0,0 +1 @@
+--color
View
3 Gemfile
@@ -0,0 +1,3 @@
+source "http://rubygems.org"
+
+gemspec
View
42 Gemfile.lock
@@ -0,0 +1,42 @@
+PATH
+ remote: .
+ specs:
+ its-it (1.0.0)
+ blankslate
+ its-it
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ blankslate (2.1.2.4)
+ diff-lcs (1.1.2)
+ git (1.2.5)
+ jeweler (1.5.2)
+ bundler (~> 1.0.0)
+ git (>= 1.2.5)
+ rake
+ rake (0.8.7)
+ rspec (2.3.0)
+ rspec-core (~> 2.3.0)
+ rspec-expectations (~> 2.3.0)
+ rspec-mocks (~> 2.3.0)
+ rspec-core (2.3.1)
+ rspec-expectations (2.3.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.3.0)
+ simplecov (0.4.2)
+ simplecov-html (~> 0.4.4)
+ simplecov-gem-adapter (1.0.1)
+ simplecov
+ simplecov-html (0.4.4)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bundler (~> 1.0.0)
+ its-it!
+ jeweler (~> 1.5.2)
+ rspec (~> 2.3.0)
+ simplecov
+ simplecov-gem-adapter
View
3 History.txt
@@ -1,3 +0,0 @@
-== 1.0.0 2007-08-04
-
-* Initial release. Blog post on Jicksta.com at http://jicksta.com/articles/2007/08/05/the-methodphitamine
View
5 License.txt → LICENSE.txt
@@ -1,4 +1,5 @@
-Copyright (c) 2007 Jay Phillips
+Original code Copyright (c) 2007 Jay Phillips
+Updates Copyright (c) 2011 Ronen Barzel
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
@@ -17,4 +18,4 @@ 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.
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
17 Manifest.txt
@@ -1,17 +0,0 @@
-History.txt
-License.txt
-Manifest.txt
-README.txt
-Rakefile
-lib/methodphitamine.rb
-lib/methodphitamine/it_class.rb
-lib/methodphitamine/monkey_patches.rb
-lib/methodphitamine/version.rb
-scripts/txt2html
-spec/methodphitamine_spec.rb
-spec/rspec_compatibility_spec.rb
-website/index.html
-website/index.txt
-website/javascripts/rounded_corners_lite.inc.js
-website/stylesheets/screen.css
-website/template.rhtml
View
53 README.markdown
@@ -1,53 +0,0 @@
-Methodphitamine
-===============
-
-The Methodphitamine is a library for syntactically cleaner list comprehensions and an interesting approach to monads in Ruby.
-
-For more information, read my [blog post](http://jicksta.com/posts/the-methodphitamine) covering the Methodphitamine.
-
-Cleaner Symbol#to_proc
-----------------------
-
-One of the beautiful things the Ruby community has informally built into the language is Symbol#to_proc. The Methodphitamine takes beauty one step further.
-
-Below are code examples which show the Methodphitamine's syntactical improvements over vanilla Ruby and Symbol#to_proc:
-
-First, the pure-Ruby way:
-
- User.find(:all).map{|x| x.contacts.map{|y| y.last_name.capitalize }}
-
-And now with Symbol#to_proc:
-
- User.find(:all).map{|x|x.contacts.map(&:last_name).map(&:capitalize)}
-
-And now with the Methodphitamine once more:
-
- User.find(:all).map &its.contacts.map(&its.last_name.capitalize)
-
-Notice how even with Symbol#to_proc a block literal is still necessary because it simply can’t do nested arguments. The Methodphitamine fixes this by preserving all arguments and being more readable to boot.
-
-New: Monads
------------
-
-You can now do something like this:
-
- my_array.maybe &it.first.reverse.upcase
-
-If the `my_array` variable were equal to `["foo", "bar", "qaz"]`, the result of the expression above would be `"OOF"`. However, if `my_array` were equal to `[]`, the result of the expression would be `nil`. This `maybe` method will execute the chain of methods if and only if all were successful. If one failed, `nil` is returned.
-
-So how does The Methodphitamine work?
--------------------------------------
-
-The `it()` and `its()` protected methods are added to `Kernel` so it can be called from anywhere in a Ruby script but not on any particular `Object` instance. They each simply return a new `It` instance.
-
-The `It` class has all instance methods stripped from it (except the ones Ruby complains about) to ensure `method_missing()` catches everything. In the example `[1,"2",3].map &its.class.name`, the `It` object first receives the `class()` method with no arguments via `method_missing()`. This gets enqueued in the `@methods` `Array` and it returns itself to receive any more methods. It then receives the next method, namely `name()`, and enqueues that alongside the previous method. When no more methods exist, Ruby determines if the `It` instance has a `to_proc()` method by calling `respond_to?(:to_proc)` so this has to be ignored and self suffices as a Ruby true boolean.
-
-Then the magic happens. Because `map()` takes a block (essentially a `Proc` argument), this can be substituted with a variable or method that returns a block as long as an ampersand prepends it to let the Ruby interpreter know to call `to_proc()` on it. The `It#to_proc()` method is invoked, building a custom, dynamic `Proc`. Because these enumerations yield a variable, the dynamic `Proc` is executed for each item in the collection and `obj` consequentially becomes a reference to the current item in the collection. We then run through the enqueued methods with `inject()`, passing along the return value of executing each method in the order received with arguments intact. When `inject()` is done, it simply returns the grand product which becomes the return value of the `Proc` itself. Simple, right? :)
-
-I chose to define both `it()` and `its()` since methods in Ruby can semantically either mean “the result of this action” or the possessive “this attribute.” For example, `it.to_s` and `it.sort_by` are both conceptual actions and `its.class.name` and `its.last` are both conceptual attributes.
-
-The idea of an it implied block argument comes from the Groovy guys. For example, this is valid Groovy:
-
- [1,2,3,4].each { println it }
-
-From the Groovy documentation on closures, “A closure always has at least one argument, which will be available within the body of the closure via the implicit parameter it if no explicit parameters are defined. The developer never has to declare the it variable – like the this parameter within objects, it is implicitly available.”
View
44 README.rdoc
@@ -0,0 +1,44 @@
+= its-it
+
+== Overview
+
+This gem defines kernel methods <code>its</code> and <code>it</code> that extend the Symbol#to_proc idiom to support chaining multiple methods.
+
+The pure Ruby way to chain methods when enumerating a list would be:
+
+ users.collect{|user| user.contact}.collect{|contact| contact.last_name}.collect{|name| name.capitalize}
+
+Using <code>Symbol#to_proc</code>, this becomes simpler:
+
+ users.collect(&:contact).collect(&:last_name).collect(&:capitalize)
+
+And using <code>its</code>, this becomes becomes simpler still:
+
+ users.collect(&its.contact.last_name.capitalize)
+
+<code>it</code> is an alias for <code>its</code>, to use with methods that
+describe actions rather than posessives. For example:
+
+ items.collect(&it.to_s.capitalize)
+
+== Installation
+
+Install from http://rubygems.org via
+
+ $ gem install "its-it"
+
+or in a Gemfile
+
+ gem "its-it"
+
+== Compatibility
+
+Tested with <b>ruby 1.8.7</b> and <b>ruby 1.9.2</b>
+
+== History
+
+This gem is a clone of Jay Philips'
+methodphitamine[https://github.com/jicksta/methodphitamine] gem, updated to
+be compatible with ruby 1.9.2 and gemspec, renamed its-it, and installed on
+rubygems.org[http://rubygems.org]. Unlike methodphitamine, this gem includes only
+<code>its</code> and <code>it</code>, not the "maybe" monad.
View
194 Rakefile
@@ -1,144 +1,62 @@
require 'rubygems'
-require 'rake'
-require 'rake/clean'
-require 'rake/testtask'
-require 'rake/packagetask'
-require 'rake/gempackagetask'
-require 'rake/rdoctask'
-require 'rake/contrib/rubyforgepublisher'
-require 'fileutils'
-require 'hoe'
-require 'spec/rake/spectask'
-
-include FileUtils
-require File.join(File.dirname(__FILE__), 'lib', 'methodphitamine', 'version')
-
-AUTHOR = 'Jay Phillips'
-EMAIL = "jay-at-codemecca.com"
-
-DESCRIPTION = %(The Methodphitamine! Creates the implied block argument "it" which makes the
-refining and enumerating of collections much simpler. For example, User.find(:all).collect
-&its.contacts.map(&its.last_name.capitalize))
-
-GEM_NAME = 'methodphitamine' # what ppl will type to install your gem
-
-@config_file = "~/.rubyforge/user-config.yml"
-@config = nil
-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 ||= @config["username"]
-end
-
-RUBYFORGE_PROJECT = 'methodphitamine' # The unix name for your project
-HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
-DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
-
-NAME = "methodphitamine"
-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 = Methodphitamine::VERSION::STRING + (REV ? ".#{REV}" : "")
-CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
-RDOC_OPTS = ['--quiet', '--title', 'methodphitamine documentation',
- "--opname", "index.html",
- "--line-numbers",
- "--main", "README",
- "--inline-source"]
-
-class Hoe
- def extra_deps
- @extra_deps.reject { |x| Array(x).first == 'hoe' }
- end
-end
-
-Spec::Rake::SpecTask.new do |opts|
- opts.spec_opts = %w'-c'
-end
-
-Spec::Rake::SpecTask.new "report" do |opts|
- opts.spec_opts = %w'--format html:report.html'
-end
-
-Spec::Rake::SpecTask.new("rcov") do |opts|
- opts.spec_files = FileList['spec/**/*_spec.rb']
- opts.rcov = true
- #opts.spec_opts = %w'-c'
-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.author = AUTHOR
- p.description = DESCRIPTION
- p.email = EMAIL
- p.summary = DESCRIPTION
- p.url = HOMEPATH
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
- p.test_globs = ["test/**/test_*.rb"]
- p.clean_globs |= CLEAN #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')
-
-desc 'Generate website files'
-task :website_generate do
- Dir['website/**/*.txt'].each do |txt|
- sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
- end
-end
-
-desc 'Upload website files to rubyforge'
-task :website_upload do
- host = "#{rubyforge_username}@rubyforge.org"
- remote_dir = "/var/www/gforge-projects/#{PATH}/"
- local_dir = 'website'
- sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
-end
-
-desc 'Generate and upload website files'
-task :website => [:website_generate, :website_upload, :publish_docs]
-
-desc 'Release the website and new gem version'
-task :deploy => [:check_version, :website, :release] do
- puts "Remember to create SVN tag:"
- puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
- "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
- puts "Suggested comment:"
- puts "Tagging release #{CHANGES}"
+require 'bundler'
+begin
+ Bundler.setup(:default, :development)
+rescue Bundler::BundlerError => e
+ $stderr.puts e.message
+ $stderr.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
end
+require 'rake'
-desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
-task :local_deploy => [:website_generate, :install_gem]
+require 'jeweler'
+require './lib/its-it/version'
+Jeweler::Tasks.new do |gem|
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
+ gem.name = "its-it"
+ gem.homepage = "http://github.com/ronen/its-it"
+ gem.license = "MIT"
+ gem.summary = %Q{Defines its() and it() method-chain proc proxies.}
+ gem.description = %Q{
+This gem defines the Kernel method "it", which extends the Symbol#to_proc
+idiom to support chaining multiple methods. For example,
+items.collect(&it.to_s.capitalize). The method is also aliased as "its",
+for methods that describe possessives rather than actions, such as
+items.collect(&its.name.capitalize)
+
+[This gem is clone of Jay Philips' "methodphitamine" gem, updated for ruby 1.9 and gemspec compatibility.]
+}
+ gem.email = "ronen@barzel.org"
+ gem.authors = ["Ronen Barzel"]
+ gem.version = ItsIt::Version::STRING
+ gem.add_runtime_dependency 'blankslate'
+ gem.add_development_dependency "rspec", "~> 2.3.0"
+ gem.add_development_dependency "bundler", "~> 1.0.0"
+ gem.add_development_dependency "jeweler", "~> 1.5.2"
+ gem.add_development_dependency "simplecov"
+ gem.add_development_dependency "simplecov-gem-adapter"
+end
+Jeweler::RubygemsDotOrgTasks.new
+
+require 'rspec/core'
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec) do |spec|
+ spec.pattern = FileList['spec/**/*_spec.rb']
+end
+
+RSpec::Core::RakeTask.new(:rcov) do |spec|
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov = true
+end
+
+task :default => :spec
-task :check_version do
- unless ENV['VERSION']
- puts 'Must pass a VERSION=x.y.z release version'
- exit
- end
- unless ENV['VERSION'] == VERS
- puts "Please update your version.rb to match the release version, currently #{VERS}"
- exit
- end
-end
+require 'rake/rdoctask'
+Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
-task :website_generate do
-
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "its-it #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
end
View
1 VERSION
@@ -0,0 +1 @@
+1.1.0
View
109 its-it.gemspec
@@ -0,0 +1,109 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{its-it}
+ s.version = "1.0.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Ronen Barzel"]
+ s.date = %q{2011-04-23}
+ s.description = %q{
+This gem defines the Kernel method "it", which extends the Symbol#to_proc
+idiom to support chaining multiple methods. For example,
+items.collect(&it.to_s.capitalize). The method is also aliased as "its",
+for methods that describe possessives rather than actions, such as
+items.collect(&its.name.capitalize)
+
+[This gem is clone of Jay Philips' "methodphitamine" gem, updated for ruby 1.9 and gemspec compatibility.]
+}
+ s.email = %q{ronen@barzel.org}
+ s.extra_rdoc_files = [
+ "LICENSE.txt",
+ "README.rdoc"
+ ]
+ s.files = [
+ "LICENSE.txt",
+ "README.rdoc",
+ "Rakefile",
+ "lib/its-it.rb",
+ "lib/its-it/it.rb",
+ "lib/its-it/kernel.rb",
+ "lib/its-it/version.rb",
+ "spec/it_spec.rb",
+ "spec/rspec_compatibility_spec.rb"
+ ]
+ s.homepage = %q{http://github.com/ronen/its-it}
+ s.licenses = ["MIT"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.7.2}
+ s.summary = %q{Defines its() and it() method-chain proc proxies.}
+ s.test_files = [
+ "spec/it_spec.rb",
+ "spec/rspec_compatibility_spec.rb",
+ "spec/spec_helper.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<its-it>, [">= 0"])
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
+ s.add_development_dependency(%q<simplecov-gem-adapter>, [">= 0"])
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
+ s.add_development_dependency(%q<simplecov-gem-adapter>, [">= 0"])
+ s.add_runtime_dependency(%q<blankslate>, [">= 0"])
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
+ s.add_development_dependency(%q<simplecov-gem-adapter>, [">= 0"])
+ else
+ s.add_dependency(%q<its-it>, [">= 0"])
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
+ s.add_dependency(%q<simplecov>, [">= 0"])
+ s.add_dependency(%q<simplecov-gem-adapter>, [">= 0"])
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
+ s.add_dependency(%q<simplecov>, [">= 0"])
+ s.add_dependency(%q<simplecov-gem-adapter>, [">= 0"])
+ s.add_dependency(%q<blankslate>, [">= 0"])
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
+ s.add_dependency(%q<simplecov>, [">= 0"])
+ s.add_dependency(%q<simplecov-gem-adapter>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<its-it>, [">= 0"])
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
+ s.add_dependency(%q<simplecov>, [">= 0"])
+ s.add_dependency(%q<simplecov-gem-adapter>, [">= 0"])
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
+ s.add_dependency(%q<simplecov>, [">= 0"])
+ s.add_dependency(%q<simplecov-gem-adapter>, [">= 0"])
+ s.add_dependency(%q<blankslate>, [">= 0"])
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
+ s.add_dependency(%q<simplecov>, [">= 0"])
+ s.add_dependency(%q<simplecov-gem-adapter>, [">= 0"])
+ end
+end
+
View
8 lib/its-it.rb
@@ -0,0 +1,8 @@
+$: << File.expand_path(File.dirname(__FILE__))
+
+require 'its-it/it'
+require 'its-it/kernel'
+require 'its-it/version'
+
+include ItsIt
+include ItsIt::Kernel
View
25 lib/methodphitamine/it_class.rb → lib/its-it/it.rb
@@ -7,13 +7,12 @@
#
# (1..10).select &it % 2 == 0
#
-# For more examples, see http://methodphitamine.rubyforge.org.
-module Methodphitamine
+module ItsIt
- # The class instantiated by the it() and its() methods from monkey_patches.rb.
+ # The class instantiated by the <code>it</code> and <code>its</code> kernel methods.
class It < BlankSlate
- def initialize
+ def initialize #:nodoc:
@methods = []
end
@@ -30,23 +29,13 @@ def to_proc
end
end
- # Used for testing this class.
- def methodphitamine_queue
+ # Used for testing. This method is hidden but can be revealed using
+ # ItsIt::It.reveal(:method_queue)
+ def method_queue
@methods
end
+ hide(:method_queue)
end
- class MethodphitamineMaybe < It
- def to_proc
- Proc.new do |obj|
- @methods.inject(obj) do |current,(args,block)|
- new_current = current.send(*args, &block)
- return current unless new_current
- new_current
- end
- end
- end
- end
-
end
View
7 lib/its-it/kernel.rb
@@ -0,0 +1,7 @@
+module ItsIt
+ module Kernel
+ protected
+ def it() It.new end
+ alias its it
+ end
+end
View
10 lib/its-it/version.rb
@@ -0,0 +1,10 @@
+module ItsIt #:nodoc:
+ module Version #:nodoc:
+ MAJOR = 1
+ MINOR = 0
+ PATCH = 0
+ BUILD = nil
+
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
+ end
+end
View
7 lib/methodphitamine.rb
@@ -1,7 +0,0 @@
-$: << File.expand_path(File.dirname(__FILE__))
-
-require 'methodphitamine/version'
-require 'methodphitamine/it_class'
-require 'methodphitamine/monkey_patches'
-
-include Methodphitamine
View
9 lib/methodphitamine/monkey_patches.rb
@@ -1,9 +0,0 @@
-module Kernel
- protected
- def it() It.new end
- alias its it
-
- def maybe(&block)
- MethodphitamineMaybe.new
- end
-end
View
9 lib/methodphitamine/version.rb
@@ -1,9 +0,0 @@
-module Methodphitamine #:nodoc:
- module VERSION #:nodoc:
- MAJOR = 1
- MINOR = 0
- TINY = 0
-
- STRING = [MAJOR, MINOR, TINY].join('.')
- end
-end
View
BIN pkg/methodphitamine-1.0.0.gem
Binary file not shown.
View
67 scripts/txt2html
@@ -1,67 +0,0 @@
-#!/usr/bin/env ruby
-
-require 'rubygems'
-require 'redcloth'
-require 'syntax/convertors/html'
-require 'erb'
-require File.dirname(__FILE__) + '/../lib/methodphitamine/version.rb'
-
-version = Methodphitamine::VERSION::STRING
-download = 'http://rubyforge.org/projects/methodphitamine'
-
-class Fixnum
- def ordinal
- # teens
- return 'th' if (10..19).include?(self % 100)
- # others
- case self % 10
- when 1: return 'st'
- when 2: return 'nd'
- when 3: return 'rd'
- else return 'th'
- end
- end
-end
-
-class Time
- def pretty
- return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
- end
-end
-
-def convert_syntax(syntax, source)
- return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
-end
-
-if ARGV.length >= 1
- src, template = ARGV
- template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
-
-else
- puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
- exit!
-end
-
-template = ERB.new(File.open(template).read)
-
-title = nil
-body = nil
-File.open(src) do |fsrc|
- title_text = fsrc.readline
- body_text = fsrc.read
- syntax_items = []
- body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
- ident = syntax_items.length
- element, syntax, source = $1, $2, $3
- syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
- "syntax-temp-#{ident}"
- }
- title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
- body = RedCloth.new(body_text).to_html
- body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
-end
-stat = File.stat(src)
-created = stat.ctime
-modified = stat.mtime
-
-$stdout << template.result(binding)
View
20 spec/methodphitamine_spec.rb → spec/it_spec.rb
@@ -1,32 +1,36 @@
-require File.dirname(__FILE__) + "/../lib/methodphitamine.rb"
+require File.dirname(__FILE__) + "/spec_helper"
describe "An It instance" do
+
+ before :all do
+ ItsIt::It.reveal(:method_queue)
+ end
before:each do
- @it = Methodphitamine::It.new
+ @it = ItsIt::It.new
end
it "should queue a single simple method" do
@it.foo
- queue = @it.methodphitamine_queue
+ queue = @it.method_queue
queue.size.should == 1
queue.first.size.should == 2
queue.first.last.should be_nil # No block, ergo nil
end
it "should store arguments" do
@it.bar(:qaz, :qwerty)
- @it.methodphitamine_queue.first.should == [[:bar, :qaz, :qwerty], nil]
+ @it.method_queue.first.should == [[:bar, :qaz, :qwerty], nil]
end
it "should store a block" do
@it.map { }
- @it.methodphitamine_queue.first.last.should be_kind_of(Proc)
+ @it.method_queue.first.last.should be_kind_of(Proc)
end
it "should allow chaining blocks" do
@it.map {}.inject {}.select {}.sexypants {}
- blocks = @it.methodphitamine_queue.map { |x| x.last }
+ blocks = @it.method_queue.map { |x| x.last }
blocks.size.should == 4
blocks.each do |block|
block.should be_kind_of(Proc)
@@ -35,7 +39,7 @@
it "should queue many methods in the right order" do
@it.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y.z
- queue = @it.methodphitamine_queue
+ queue = @it.method_queue
queue.size.should == 26
queue.map { |x| x.first.first.to_s }.should == ('a'..'z').to_a
end
@@ -46,7 +50,7 @@
it "should not queue the method respond_to? when given :to_proc as an arg" do
@it.respond_to? :to_proc
- @it.methodphitamine_queue.should be_empty
+ @it.method_queue.should be_empty
end
end
View
29 spec/monad_spec.rb
@@ -1,29 +0,0 @@
-require 'ostruct'
-require File.dirname(__FILE__) + "/../lib/methodphitamine.rb"
-
-describe "The maybe() method" do
- it "should return nil when a link in a chain of methods returns nil before all methods are done executing" do
- mary = {"mary" => {}}
- hash = {'mary' => mary}
- long_search = hash.maybe &it['mary']['had']['a']['little']['lamb'].fleece.color == :white_as_snow
- long_search.should eql(mary)
- end
-
- it "should return the last return value in a chain of methods if all returned non-nil values" do
- test = "foo bar"
- test.maybe &it.reverse.upcase.chop.reverse
- test.should be_kind_of(String)
- end
-
- it "should also break the method chain when a link in the chain returns false" do
- one = OpenStruct.new
- two = OpenStruct.new
-
- one.foo = two
- two.bar = false
-
- value = one.maybe &it.two.bar.upcase.reverse
- value.should eql(two)
- end
-
-end
View
8 spec/rspec_compatibility_spec.rb
@@ -1,6 +1,6 @@
-require File.dirname(__FILE__) + "/../lib/methodphitamine.rb"
+require File.dirname(__FILE__) + "/spec_helper"
-describe "The Methodphitamine's RSpec compatibility" do
+describe "The ItsIt's RSpec compatibility" do
# Surprisingly, RSpec's it() method isn't even defined within the context
# of each expectation block. Man, that's some crazy voodoo.
@@ -10,11 +10,11 @@
should respond_to(:its)
method(:it).should == method(:its) # Ensure it's not RSpec's it() method
lambda do
- it.should be_kind_of(Methodphitamine::It)
+ it.should be_kind_of(ItsIt::It)
end.should_not raise_error
end
it "should work with RSpec's assertion methods" do
[1,2,3].each &it.should(be_kind_of(Fixnum))
end
-end
+end
View
18 spec/spec_helper.rb
@@ -0,0 +1,18 @@
+if RUBY_VERSION > "1.9"
+ require 'simplecov'
+ require 'simplecov-gem-adapter'
+ SimpleCov.start 'gem'
+end
+
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+require 'rspec'
+require 'its-it'
+
+# Requires supporting files with custom matchers and macros, etc,
+# in ./support/ and its subdirectories.
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+
+RSpec.configure do |config|
+
+end

0 comments on commit 735776a

Please sign in to comment.