its-it 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -95,13 +95,16 @@ or in a Gemfile
95
95
 
96
96
  == Compatibility
97
97
 
98
- Tested with <b>ruby 1.8.7</b> and <b>ruby 1.9.2</b>
98
+ Works with MRI ruby 1.8.7, 1.9.2, 1.9.3
99
99
 
100
100
  == History
101
101
 
102
102
  This gem is orignally based on Jay Philips'
103
103
  methodphitamine[https://github.com/jicksta/methodphitamine] gem. It has
104
- been updated to be compatible with ruby 1.9.2 and gemspec, renamed its-it,
105
- and installed on rubygems.org[http://rubygems.org]. Unlike
106
- methodphitamine, this gem includes only <code>its</code> and
107
- <code>it</code>, not the "maybe" monad.
104
+ been updated to be compatible with ruby 1.9 and gemspec, added case
105
+ statement support, renamed its-it, and installed on
106
+ rubygems.org[http://rubygems.org]. Unlike methodphitamine, this gem
107
+ includes only <code>its</code> and <code>it</code>, not the "maybe" monad.
108
+
109
+ Release Notes
110
+ * 1.1.1 Remove dependency on BlankSlate
data/Rakefile CHANGED
@@ -30,7 +30,8 @@ end
30
30
 
31
31
  task :default => :spec
32
32
 
33
- require 'rake/rdoctask'
33
+ require "rdoc/task"
34
+
34
35
  Rake::RDocTask.new do |rdoc|
35
36
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
36
37
 
@@ -35,7 +35,7 @@ for ruby 1.9 and gemspec compatibility and adding the case statement functionali
35
35
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
36
36
  s.require_paths = ['lib']
37
37
 
38
- s.add_runtime_dependency 'blankslate'
38
+ s.add_development_dependency 'rdoc'
39
39
  s.add_development_dependency 'rspec'
40
40
  s.add_development_dependency 'bundler'
41
41
  s.add_development_dependency 'bueller'
@@ -1,4 +1,4 @@
1
- require 'blankslate'
1
+ #require 'blankslate' unless defined? BasicObject
2
2
 
3
3
  # This module contains an It class which queues any methods called on it
4
4
  # and can be converted into a Proc. The Proc it generates executes the queued
@@ -8,38 +8,36 @@ require 'blankslate'
8
8
  # (1..10).select &it % 2 == 0
9
9
  #
10
10
  module ItsIt
11
-
11
+
12
12
  # The class instantiated by the <code>it</code> and <code>its</code> kernel methods.
13
- class It < BlankSlate
13
+ class It < (defined?(BasicObject) ? BasicObject : Object)
14
+
15
+ instance_methods.map(&:to_s).each do |method|
16
+ undef_method method unless method.start_with? "__"
17
+ end
14
18
 
15
19
  def initialize #:nodoc:
16
20
  @methods = []
17
21
  end
18
22
 
19
23
  def method_missing(*args, &block)
20
- @methods << [args, block] unless args.first == :respond_to? and [:to_proc, :===].include?(args[1])
24
+ @methods << [args, block] unless args.first == :respond_to? and [:to_proc, :===].include?(args[1].to_sym)
21
25
  self
22
26
  end
23
-
27
+
24
28
  def to_proc
25
- lambda do |obj|
26
- @methods.inject(obj) do |current,(args,block)|
29
+ Kernel.send :lambda do |obj|
30
+ ret = @methods.inject(obj) do |current,(args,block)|
27
31
  current.send(*args, &block)
28
32
  end
33
+ ret
29
34
  end
30
35
  end
31
36
 
32
37
  def ===(obj)
33
- to_proc.call(obj)
38
+ self.to_proc.call(obj)
34
39
  end
35
40
 
36
- # Used for testing. This method is hidden but can be revealed using
37
- # ItsIt::It.reveal(:method_queue)
38
- def method_queue
39
- @methods
40
- end
41
- hide(:method_queue)
42
-
43
41
  end
44
42
 
45
43
  end
@@ -1,3 +1,3 @@
1
1
  module ItsIt
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -2,54 +2,51 @@ require File.dirname(__FILE__) + "/spec_helper"
2
2
 
3
3
  describe "An It instance" do
4
4
 
5
- before :all do
6
- ItsIt::It.reveal(:method_queue)
5
+ before (:each) do
6
+ it = ItsIt::It.new
7
+ @string = "This is a test"
7
8
  end
8
-
9
- before:each do
10
- @it = ItsIt::It.new
9
+
10
+ it "should start with identity via to_proc" do
11
+ it.to_proc.call(@string).should == @string
11
12
  end
12
-
13
- it "should queue a single simple method" do
14
- @it.foo
15
- queue = @it.method_queue
16
- queue.size.should == 1
17
- queue.first.size.should == 2
18
- queue.first.last.should be_nil # No block, ergo nil
13
+
14
+ it "should start with identity via ===" do
15
+ (it === @string).should == @string
19
16
  end
20
-
21
- it "should store arguments" do
22
- @it.bar(:qaz, :qwerty)
23
- @it.method_queue.first.should == [[:bar, :qaz, :qwerty], nil]
17
+
18
+ it "should work with a simple method via to_proc" do
19
+ (it.length).to_proc.call(@string).should == @string.length
20
+ end
21
+
22
+ it "should work with a simple methoud using ===" do
23
+ ((it.length) === @string).should == @string.length
24
24
  end
25
25
 
26
- it "should store a block" do
27
- @it.map { }
28
- @it.method_queue.first.last.should be_kind_of(Proc)
26
+ it "should work with arguments" do
27
+ (it.sub(/test/, 'kumquat')).call(@string).should == 'This is a kumquat'
29
28
  end
30
29
 
31
- it "should allow chaining blocks" do
32
- @it.map {}.inject {}.select {}.sexypants {}
33
- blocks = @it.method_queue.map { |x| x.last }
34
- blocks.size.should == 4
35
- blocks.each do |block|
36
- block.should be_kind_of(Proc)
37
- end
30
+ it "should work with a block" do
31
+ (it.sub(/test/) {"balloon"}).to_proc.call(@string).should == 'This is a balloon'
38
32
  end
39
33
 
40
- it "should queue many methods in the right order" do
41
- @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
42
- queue = @it.method_queue
43
- queue.size.should == 26
44
- queue.map { |x| x.first.first.to_s }.should == ('a'..'z').to_a
34
+ it "should chain methods" do
35
+ it.reverse.swapcase.succ.should == "TSET A SI SIHu"
45
36
  end
46
37
 
47
38
  it "should respond to to_proc()" do
48
- @it.should respond_to(:to_proc)
39
+ it.should respond_to(:to_proc)
49
40
  end
50
41
 
51
42
  it "should respond to ===" do
52
- @it.should respond_to(:===)
43
+ it.should respond_to(:===)
44
+ end
45
+
46
+ it "should work with numbers" do
47
+ ((it < 1) === 0).should be_true
48
+ ((it < 1) === 1).should be_false
49
+ ((it < 1) === 2).should be_false
53
50
  end
54
51
 
55
52
  it "should work in a case statement" do
@@ -63,13 +60,15 @@ describe "An It instance" do
63
60
  end
64
61
 
65
62
  it "should not queue the method respond_to? when given :to_proc as an arg" do
66
- @it.respond_to? :to_proc
67
- @it.method_queue.should be_empty
63
+ (it.respond_to? :to_proc).should be_true
68
64
  end
69
65
 
70
66
  it "should not queue the method respond_to? when given :=== as an arg" do
71
- @it.respond_to? :to_proc
72
- @it.method_queue.should be_empty
67
+ (it.respond_to? :===).should be_true
68
+ end
69
+
70
+ it "should queue the method respond_to? when given generic arg" do
71
+ (it.respond_to? :size).to_proc.call(@string).should be_true
73
72
  end
74
73
 
75
74
  end
metadata CHANGED
@@ -1,102 +1,109 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: its-it
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.1
4
5
  prerelease:
5
- version: 1.1.0
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Ronen Barzel
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-04-26 00:00:00 -07:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- name: blankslate
18
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2011-04-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: &70172872051900 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- type: :runtime
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
25
23
  prerelease: false
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
24
+ version_requirements: *70172872051900
25
+ - !ruby/object:Gem::Dependency
28
26
  name: rspec
29
- requirement: &id002 !ruby/object:Gem::Requirement
27
+ requirement: &70172872051440 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
35
33
  type: :development
36
34
  prerelease: false
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
35
+ version_requirements: *70172872051440
36
+ - !ruby/object:Gem::Dependency
39
37
  name: bundler
40
- requirement: &id003 !ruby/object:Gem::Requirement
38
+ requirement: &70172872050980 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: "0"
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
46
44
  type: :development
47
45
  prerelease: false
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
46
+ version_requirements: *70172872050980
47
+ - !ruby/object:Gem::Dependency
50
48
  name: bueller
51
- requirement: &id004 !ruby/object:Gem::Requirement
49
+ requirement: &70172872044640 !ruby/object:Gem::Requirement
52
50
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
57
55
  type: :development
58
56
  prerelease: false
59
- version_requirements: *id004
60
- - !ruby/object:Gem::Dependency
57
+ version_requirements: *70172872044640
58
+ - !ruby/object:Gem::Dependency
61
59
  name: simplecov
62
- requirement: &id005 !ruby/object:Gem::Requirement
60
+ requirement: &70172872044220 !ruby/object:Gem::Requirement
63
61
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
68
66
  type: :development
69
67
  prerelease: false
70
- version_requirements: *id005
71
- - !ruby/object:Gem::Dependency
68
+ version_requirements: *70172872044220
69
+ - !ruby/object:Gem::Dependency
72
70
  name: simplecov-gem-adapter
73
- requirement: &id006 !ruby/object:Gem::Requirement
71
+ requirement: &70172872043800 !ruby/object:Gem::Requirement
74
72
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
79
77
  type: :development
80
78
  prerelease: false
81
- version_requirements: *id006
82
- description: "\n\
83
- This gem defines the Kernel method \"it\" that queue and defer method calls.\n\
84
- This extends the Symbol#to_proc idiom to support chaining multiple methods.\n\
85
- For example, items.collect(&it.to_s.capitalize). This also allows\n\
86
- conditionals in case statements, such as: case ... when it > 3 then [etc.].\n\
87
- The method is also aliased as \"its\", for methods that describe possessives\n\
88
- rather than actions, such as items.collect(&its.name.capitalize)\n\n\
89
- [This gem is an extension of Jay Philips' \"methodphitamine\" gem, updated\n\
90
- for ruby 1.9 and gemspec compatibility and adding the case statement functionality.]\n"
79
+ version_requirements: *70172872043800
80
+ description: ! '
81
+
82
+ This gem defines the Kernel method "it" that queue and defer method calls.
83
+
84
+ This extends the Symbol#to_proc idiom to support chaining multiple methods.
85
+
86
+ For example, items.collect(&it.to_s.capitalize). This also allows
87
+
88
+ conditionals in case statements, such as: case ... when it > 3 then [etc.].
89
+
90
+ The method is also aliased as "its", for methods that describe possessives
91
+
92
+ rather than actions, such as items.collect(&its.name.capitalize)
93
+
94
+
95
+ [This gem is an extension of Jay Philips'' "methodphitamine" gem, updated
96
+
97
+ for ruby 1.9 and gemspec compatibility and adding the case statement functionality.]
98
+
99
+ '
91
100
  email: ronen@barzel.org
92
101
  executables: []
93
-
94
102
  extensions: []
95
-
96
- extra_rdoc_files:
103
+ extra_rdoc_files:
97
104
  - LICENSE.txt
98
105
  - README.rdoc
99
- files:
106
+ files:
100
107
  - .document
101
108
  - .gitignore
102
109
  - .rspec
@@ -112,38 +119,34 @@ files:
112
119
  - spec/it_spec.rb
113
120
  - spec/rspec_compatibility_spec.rb
114
121
  - spec/spec_helper.rb
115
- has_rdoc: true
116
122
  homepage: http://github.com/ronen/its-it
117
123
  licenses: []
118
-
119
124
  post_install_message:
120
125
  rdoc_options: []
121
-
122
- require_paths:
126
+ require_paths:
123
127
  - lib
124
- required_ruby_version: !ruby/object:Gem::Requirement
128
+ required_ruby_version: !ruby/object:Gem::Requirement
125
129
  none: false
126
- requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- hash: -664830529632804485
130
- segments:
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ segments:
131
135
  - 0
132
- version: "0"
133
- required_rubygems_version: !ruby/object:Gem::Requirement
136
+ hash: -4170040046291894423
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
138
  none: false
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
138
142
  version: 1.3.7
139
143
  requirements: []
140
-
141
144
  rubyforge_project:
142
- rubygems_version: 1.6.2
145
+ rubygems_version: 1.8.6
143
146
  signing_key:
144
147
  specification_version: 3
145
148
  summary: Defines its() and it() method-chain proxies.
146
- test_files:
149
+ test_files:
147
150
  - spec/it_spec.rb
148
151
  - spec/rspec_compatibility_spec.rb
149
152
  - spec/spec_helper.rb