visionmedia-rext 0.1.0 → 0.2.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/History.rdoc CHANGED
@@ -1,4 +1,18 @@
1
1
 
2
+ === 0.2.1 / 2009-06-10
3
+
4
+ * Removed BasicObject due to compatibility issues with other libraries
5
+
6
+ === 0.2.0 / 2009-06-10
7
+
8
+ * Added Enumerable#includes_all?
9
+
10
+ === 0.1.1 / 2009-06-10
11
+
12
+ * Removed sketchy BasicObject #method_added hack for now
13
+ * Added Module#setup
14
+ * Added / Implemented Object#returning
15
+
2
16
  === 0.1.0 / 2009-05-04
3
17
 
4
18
  * Added Module#call_method
data/Manifest CHANGED
@@ -4,8 +4,6 @@ History.rdoc
4
4
  lib/rext/all.rb
5
5
  lib/rext/array/helpers.rb
6
6
  lib/rext/array.rb
7
- lib/rext/compat/basic_object.rb
8
- lib/rext/compat.rb
9
7
  lib/rext/date/helpers.rb
10
8
  lib/rext/date.rb
11
9
  lib/rext/enumerable/helpers.rb
@@ -36,7 +34,6 @@ Rakefile
36
34
  README.rdoc
37
35
  rext.gemspec
38
36
  spec/array_spec.rb
39
- spec/compat_spec.rb
40
37
  spec/date_spec.rb
41
38
  spec/enumerable_spec.rb
42
39
  spec/hash_spec.rb
data/README.rdoc CHANGED
@@ -37,6 +37,7 @@ Below are the methods currently provided by Rext.
37
37
  - meta_def
38
38
  - meta_eval
39
39
  - indifferent_hash
40
+ - returning
40
41
 
41
42
  * String
42
43
  - url_encode
@@ -60,6 +61,8 @@ Below are the methods currently provided by Rext.
60
61
  - files
61
62
  - path
62
63
  - switchify
64
+ - word_frequency
65
+ - frequency_of_word
63
66
 
64
67
  * Integer
65
68
  - ordanalize
@@ -84,18 +87,15 @@ Below are the methods currently provided by Rext.
84
87
 
85
88
  * Module
86
89
  - chain
90
+ - call_method
87
91
 
88
92
  * Proc
89
93
  - yield_or_eval
90
94
 
91
95
  * Enumerable
92
96
  - group_by
93
- - every ( Copyright http://github.com/mynyml )
94
-
95
- == Compatibility
96
-
97
- Rext provides methods which support Ruby 1.8.x and 1.9.x, as
98
- well as forward compatibility for features such as BasicObject.
97
+ - includes_all?
98
+ - every
99
99
 
100
100
  == Contrib
101
101
 
@@ -51,13 +51,13 @@ class Array
51
51
  #
52
52
 
53
53
  def chunk n, pad_with = nil, &block
54
- chunks = []
55
- each_slice n do |chunk|
56
- chunk.pad n, pad_with unless pad_with == false
57
- yield chunk if block
58
- chunks << chunk
54
+ returning [] do |chunks|
55
+ each_slice n do |chunk|
56
+ chunk.pad n, pad_with unless pad_with == false
57
+ yield chunk if block
58
+ chunks << chunk
59
+ end
59
60
  end
60
- chunks
61
61
  end
62
62
  alias :in_groups_of :chunk
63
63
 
@@ -20,7 +20,9 @@ module Enumerable
20
20
  # * Enumerable#proxy
21
21
  #
22
22
 
23
- class Proxy < BasicObject
23
+ class Proxy
24
+ instance_methods.each { |m| undef_method m unless m.match(/^__/) }
25
+
24
26
  def initialize object, meth
25
27
  @object, @method = object, meth
26
28
  end
@@ -71,4 +73,17 @@ module Enumerable
71
73
  block ? proxy(:map).instance_eval(&block) : proxy(:map)
72
74
  end
73
75
 
76
+ ##
77
+ # Check if all +args+ are included.
78
+ #
79
+ # === Examples
80
+ #
81
+ # permissions = 'save', 'edit', 'delete'
82
+ # permissions.includes_all? 'save', 'edit' # => true
83
+ #
84
+
85
+ def includes_all? *args
86
+ args.all? { |arg| include? arg }
87
+ end
88
+
74
89
  end
@@ -1,4 +1,6 @@
1
1
 
2
+ require 'rext/object/metaclass'
3
+
2
4
  class Module
3
5
 
4
6
  ##
@@ -50,4 +52,27 @@ class Module
50
52
  }
51
53
  end
52
54
 
55
+ ##
56
+ # Equivalent to defining self.included and
57
+ # instance evaluating the module passed.
58
+ #
59
+ # === Examples
60
+ #
61
+ # def self.included mod
62
+ # mod.instance_eval do
63
+ # include InstanceMethods
64
+ # end
65
+ # end
66
+ #
67
+ # setup do
68
+ # include InstanceMethods
69
+ # end
70
+ #
71
+
72
+ def setup &block
73
+ meta_def :included do |mod|
74
+ mod.instance_eval &block
75
+ end
76
+ end
77
+
53
78
  end
@@ -1,11 +1,11 @@
1
1
 
2
2
  class Numeric
3
3
 
4
- def bytes; self end
5
- def kilobytes; self * 1024 end
6
- def megabytes; self * 1024.kilobytes end
7
- def gigabytes; self * 1024.megabytes end
8
- def terabytes; self * 1024.gigabytes end
4
+ def bytes; self end
5
+ def kilobytes; self << 10 end
6
+ def megabytes; self << 20 end
7
+ def gigabytes; self << 30 end
8
+ def terabytes; self << 40 end
9
9
 
10
10
  alias :byte :bytes
11
11
  alias :kilobyte :kilobytes
@@ -18,4 +18,24 @@ class Object
18
18
  Hash.new { |hash, key| hash[key.to_s] if key.is_a? Symbol }
19
19
  end
20
20
 
21
+ ##
22
+ # Yield and return +value+.
23
+ #
24
+ # === Examples
25
+ #
26
+ # people = []
27
+ # people << 'tj'
28
+ # people << 'foo'
29
+ #
30
+ # returning [] do |people|
31
+ # people << 'tj'
32
+ # people << 'foo'
33
+ # end
34
+ #
35
+
36
+ def returning value, &block
37
+ yield value
38
+ value
39
+ end
40
+
21
41
  end
@@ -249,6 +249,8 @@ class String
249
249
  word_frequency[word]
250
250
  end
251
251
 
252
+ class InvalidSwitchError < StandardError; end
253
+
252
254
  ##
253
255
  # Returns the switch equivilant of this string.
254
256
  #
@@ -260,8 +262,6 @@ class String
260
262
  # ''.switchify # => InvalidSwitchError
261
263
  #
262
264
 
263
- class InvalidSwitchError < StandardError; end
264
-
265
265
  def switchify
266
266
  raise InvalidSwitchError, 'switch must have a length > 0' if length.zero?
267
267
  length > 1 ? "--#{dasherize}" : "-#{self}"
data/lib/rext/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rext
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.1'
4
4
  end
data/rext.gemspec CHANGED
@@ -2,21 +2,20 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rext}
5
- s.version = "0.1.0"
5
+ s.version = "0.2.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["TJ Holowaychuk"]
9
- s.date = %q{2009-05-04}
9
+ s.date = %q{2009-06-10}
10
10
  s.description = %q{Ruby extensions}
11
11
  s.email = %q{tj@vision-media.ca}
12
- s.extra_rdoc_files = ["lib/rext/all.rb", "lib/rext/array/helpers.rb", "lib/rext/array.rb", "lib/rext/compat/basic_object.rb", "lib/rext/compat.rb", "lib/rext/date/helpers.rb", "lib/rext/date.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/hash/helpers.rb", "lib/rext/hash.rb", "lib/rext/integer/helpers.rb", "lib/rext/integer.rb", "lib/rext/module/helpers.rb", "lib/rext/module.rb", "lib/rext/numeric/bytes.rb", "lib/rext/numeric/time.rb", "lib/rext/numeric.rb", "lib/rext/object/helpers.rb", "lib/rext/object/metaclass.rb", "lib/rext/object.rb", "lib/rext/proc/helpers.rb", "lib/rext/proc.rb", "lib/rext/string/escape.rb", "lib/rext/string/helpers.rb", "lib/rext/string.rb", "lib/rext/time/helpers.rb", "lib/rext/time.rb", "lib/rext/version.rb", "lib/rext.rb", "README.rdoc", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
13
- s.files = ["benchmarks/enumerable.rb", "benchmarks/proc.rb", "History.rdoc", "lib/rext/all.rb", "lib/rext/array/helpers.rb", "lib/rext/array.rb", "lib/rext/compat/basic_object.rb", "lib/rext/compat.rb", "lib/rext/date/helpers.rb", "lib/rext/date.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/hash/helpers.rb", "lib/rext/hash.rb", "lib/rext/integer/helpers.rb", "lib/rext/integer.rb", "lib/rext/module/helpers.rb", "lib/rext/module.rb", "lib/rext/numeric/bytes.rb", "lib/rext/numeric/time.rb", "lib/rext/numeric.rb", "lib/rext/object/helpers.rb", "lib/rext/object/metaclass.rb", "lib/rext/object.rb", "lib/rext/proc/helpers.rb", "lib/rext/proc.rb", "lib/rext/string/escape.rb", "lib/rext/string/helpers.rb", "lib/rext/string.rb", "lib/rext/time/helpers.rb", "lib/rext/time.rb", "lib/rext/version.rb", "lib/rext.rb", "Manifest", "Rakefile", "README.rdoc", "rext.gemspec", "spec/array_spec.rb", "spec/compat_spec.rb", "spec/date_spec.rb", "spec/enumerable_spec.rb", "spec/hash_spec.rb", "spec/integer_spec.rb", "spec/module_spec.rb", "spec/numeric_spec.rb", "spec/object_spec.rb", "spec/spec_helper.rb", "spec/string_spec.rb", "spec/time_spec.rb", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
14
- s.has_rdoc = true
12
+ s.extra_rdoc_files = ["lib/rext/all.rb", "lib/rext/array/helpers.rb", "lib/rext/array.rb", "lib/rext/date/helpers.rb", "lib/rext/date.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/hash/helpers.rb", "lib/rext/hash.rb", "lib/rext/integer/helpers.rb", "lib/rext/integer.rb", "lib/rext/module/helpers.rb", "lib/rext/module.rb", "lib/rext/numeric/bytes.rb", "lib/rext/numeric/time.rb", "lib/rext/numeric.rb", "lib/rext/object/helpers.rb", "lib/rext/object/metaclass.rb", "lib/rext/object.rb", "lib/rext/proc/helpers.rb", "lib/rext/proc.rb", "lib/rext/string/escape.rb", "lib/rext/string/helpers.rb", "lib/rext/string.rb", "lib/rext/time/helpers.rb", "lib/rext/time.rb", "lib/rext/version.rb", "lib/rext.rb", "README.rdoc", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
13
+ s.files = ["benchmarks/enumerable.rb", "benchmarks/proc.rb", "History.rdoc", "lib/rext/all.rb", "lib/rext/array/helpers.rb", "lib/rext/array.rb", "lib/rext/date/helpers.rb", "lib/rext/date.rb", "lib/rext/enumerable/helpers.rb", "lib/rext/enumerable.rb", "lib/rext/hash/helpers.rb", "lib/rext/hash.rb", "lib/rext/integer/helpers.rb", "lib/rext/integer.rb", "lib/rext/module/helpers.rb", "lib/rext/module.rb", "lib/rext/numeric/bytes.rb", "lib/rext/numeric/time.rb", "lib/rext/numeric.rb", "lib/rext/object/helpers.rb", "lib/rext/object/metaclass.rb", "lib/rext/object.rb", "lib/rext/proc/helpers.rb", "lib/rext/proc.rb", "lib/rext/string/escape.rb", "lib/rext/string/helpers.rb", "lib/rext/string.rb", "lib/rext/time/helpers.rb", "lib/rext/time.rb", "lib/rext/version.rb", "lib/rext.rb", "Manifest", "Rakefile", "README.rdoc", "rext.gemspec", "spec/array_spec.rb", "spec/date_spec.rb", "spec/enumerable_spec.rb", "spec/hash_spec.rb", "spec/integer_spec.rb", "spec/module_spec.rb", "spec/numeric_spec.rb", "spec/object_spec.rb", "spec/spec_helper.rb", "spec/string_spec.rb", "spec/time_spec.rb", "tasks/benchmark.rake", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
15
14
  s.homepage = %q{http://github.com/visionmedia/rext}
16
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rext", "--main", "README.rdoc"]
17
16
  s.require_paths = ["lib"]
18
17
  s.rubyforge_project = %q{rext}
19
- s.rubygems_version = %q{1.3.2}
18
+ s.rubygems_version = %q{1.3.4}
20
19
  s.summary = %q{Ruby extensions}
21
20
 
22
21
  if s.respond_to? :specification_version then
@@ -2,22 +2,18 @@
2
2
  require 'rext/enumerable'
3
3
 
4
4
  describe Enumerable do
5
-
6
- describe "#every" do
7
- it "should map a method call" do
8
- list = %w( cookies icecream sugar )
9
- list.every.length.should == [7, 8 ,5]
5
+ describe "helpers" do
6
+ describe "#includes_all?" do
7
+ it "should return true when all arguments are present" do
8
+ [1,2,3].includes_all?(1,2).should be_true
9
+ end
10
+
11
+ it "should return true when not all arguments are present" do
12
+ [1,1,3,3,4].includes_all?(1,3,6).should be_false
13
+ [1,1,3,3,4].includes_all?(6,3,1).should be_false
14
+ end
10
15
  end
11
16
 
12
- it "should allow mapping shortcuts using a block" do
13
- people = []
14
- people << mock('Person', :name => 'TJ')
15
- people << mock('Person', :name => 'Scott')
16
- people.every { name.length }.should == [2, 5]
17
- end
18
- end
19
-
20
- describe "helpers" do
21
17
  describe "#group_by" do
22
18
  before :each do
23
19
  @enum = 'foo', :bar, 1, 2, 3
@@ -40,6 +36,19 @@ describe Enumerable do
40
36
  @enum.group_by.class.should == @results
41
37
  end
42
38
  end
39
+
40
+ describe "#every" do
41
+ it "should map a method call" do
42
+ list = %w( cookies icecream sugar )
43
+ list.every.length.should == [7, 8 ,5]
44
+ end
45
+
46
+ it "should allow mapping shortcuts using a block" do
47
+ people = []
48
+ people << mock('Person', :name => 'TJ')
49
+ people << mock('Person', :name => 'Scott')
50
+ people.every { name.length }.should == [2, 5]
51
+ end
52
+ end
43
53
  end
44
-
45
54
  end
data/spec/module_spec.rb CHANGED
@@ -18,5 +18,23 @@ describe Module do
18
18
  lambda { foo.does_not_exist }.should raise_error(NoMethodError)
19
19
  end
20
20
  end
21
+
22
+ describe "#setup" do
23
+ it "should define included instance evaluated in context to the module passed" do
24
+ module BarFoo
25
+ setup do
26
+ include InstanceMethods
27
+ end
28
+
29
+ module InstanceMethods
30
+ def bar_foo
31
+ 'wahoo'
32
+ end
33
+ end
34
+ end
35
+ FooBar.send :include, BarFoo
36
+ FooBar.new.bar_foo.should == 'wahoo'
37
+ end
38
+ end
21
39
  end
22
40
  end
data/spec/numeric_spec.rb CHANGED
@@ -17,4 +17,14 @@ describe Numeric do
17
17
  end
18
18
  end
19
19
  end
20
+
21
+ describe "bytes" do
22
+ it "should return bytes, kilobytes, megabytes, gigabytes, and terabytes" do
23
+ 5.bytes.should == 5
24
+ 5.kilobytes.should == 5120
25
+ 5.megabytes.should == 5242880
26
+ 5.gigabytes.should == 5368709120
27
+ 5.terabytes.should == 5497558138880
28
+ end
29
+ end
20
30
  end
data/spec/object_spec.rb CHANGED
@@ -50,4 +50,20 @@ describe Object do
50
50
  end
51
51
  end
52
52
  end
53
+
54
+ describe "#returning" do
55
+ it "should return the value given to it" do
56
+ def frequency_of enum
57
+ returning Hash.new(0) do |hash|
58
+ enum.each do |value|
59
+ hash[value] += 1
60
+ end
61
+ end
62
+ end
63
+ frequency_of(%w( foo bar foo foo )).should == {
64
+ 'foo' => 3,
65
+ 'bar' => 1,
66
+ }
67
+ end
68
+ end
53
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: visionmedia-rext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TJ Holowaychuk
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-04 00:00:00 -07:00
12
+ date: 2009-06-10 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -23,8 +23,6 @@ extra_rdoc_files:
23
23
  - lib/rext/all.rb
24
24
  - lib/rext/array/helpers.rb
25
25
  - lib/rext/array.rb
26
- - lib/rext/compat/basic_object.rb
27
- - lib/rext/compat.rb
28
26
  - lib/rext/date/helpers.rb
29
27
  - lib/rext/date.rb
30
28
  - lib/rext/enumerable/helpers.rb
@@ -62,8 +60,6 @@ files:
62
60
  - lib/rext/all.rb
63
61
  - lib/rext/array/helpers.rb
64
62
  - lib/rext/array.rb
65
- - lib/rext/compat/basic_object.rb
66
- - lib/rext/compat.rb
67
63
  - lib/rext/date/helpers.rb
68
64
  - lib/rext/date.rb
69
65
  - lib/rext/enumerable/helpers.rb
@@ -94,7 +90,6 @@ files:
94
90
  - README.rdoc
95
91
  - rext.gemspec
96
92
  - spec/array_spec.rb
97
- - spec/compat_spec.rb
98
93
  - spec/date_spec.rb
99
94
  - spec/enumerable_spec.rb
100
95
  - spec/hash_spec.rb
@@ -109,7 +104,7 @@ files:
109
104
  - tasks/docs.rake
110
105
  - tasks/gemspec.rake
111
106
  - tasks/spec.rake
112
- has_rdoc: true
107
+ has_rdoc: false
113
108
  homepage: http://github.com/visionmedia/rext
114
109
  post_install_message:
115
110
  rdoc_options:
@@ -1,16 +0,0 @@
1
-
2
- require 'rext/module/helpers'
3
-
4
- class BasicObject
5
- instance_methods.each { |m| undef_method m unless m.match(/^__/) }
6
- end
7
-
8
- module RemoveBasicObjectMethods
9
- def method_added name
10
- BasicObject.send :undef_method, name if self == Object
11
- super
12
- end
13
- end
14
-
15
- Object.extend RemoveBasicObjectMethods
16
- Kernel.extend RemoveBasicObjectMethods
data/lib/rext/compat.rb DELETED
@@ -1,6 +0,0 @@
1
-
2
- #--
3
- # Load Compatibility specific rext extensions.
4
- #++
5
-
6
- require 'rext/compat/basic_object' unless defined? BasicObject
data/spec/compat_spec.rb DELETED
@@ -1,28 +0,0 @@
1
-
2
- require 'rext/compat'
3
-
4
- describe Rext do
5
- describe "compatibility" do
6
- describe BasicObject do
7
-
8
- before :each do
9
- @object = BasicObject.new
10
- end
11
-
12
- it "should have no methods" do
13
- lambda { @object.send }.should raise_error(NoMethodError)
14
- end
15
-
16
- it "should preserve __* methods" do
17
- lambda { @object.__send__ }.should_not raise_error(NoMethodError)
18
- end
19
-
20
- it "should now allow additional ancestor methods to be accessed" do
21
- module Kernel; def foo; end end
22
- class Object; def foo; end end
23
- lambda { @object.foo }.should raise_error(NoMethodError)
24
- end
25
-
26
- end
27
- end
28
- end