monkey-lib 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  module Monkey
2
-
3
2
  def self.backend=(backend)
4
3
  Backend.setup! backend
5
4
  backend
@@ -54,5 +53,4 @@ module Monkey
54
53
  filename = File.basename(path, '.rb')
55
54
  require "monkey/#{filename}"
56
55
  end
57
-
58
56
  end
@@ -2,15 +2,23 @@ Monkey::Backend.new :ActiveSupport, :active_support do
2
2
  def setup
3
3
  load_lib :version
4
4
  expects_module "::ActiveSupport::CoreExtensions::String::Inflections" if version < "3"
5
- load_libs "core_ext/object" => [:singleton_class, :misc], :core_ext => %w[array/extract_options string/inflections module/introspection]
5
+ load_libs :core_ext => %w[array/extract_options string/inflections module/introspection]
6
6
  if version < "3"
7
- ::Array.send :include, ::ActiveSupport::CoreExtensions::Array::ExtractOptions
7
+ begin
8
+ load_libs "core_ext/object/singleton_class"
9
+ rescue LoadError
10
+ load_libs "core_ext/object/metaclass"
11
+ ::Object.send(:alias_method, :singleton_class, :metaclass)
12
+ end
13
+ load_libs "core_ext/object/misc"
14
+ ::Array.send :include, ::ActiveSupport::CoreExtensions::Array::ExtractOptions
8
15
  ::Module.send :include, ::ActiveSupport::CoreExtensions::Module
16
+ ::String.send :include, ::ActiveSupport::CoreExtensions::String::Inflections
17
+ else
18
+ load_libs "core_ext/kernel/singleton_class"
9
19
  end
10
- ::String.class_eval do
11
- alias to_const_string camelcase
12
- alias to_const_path underscore
13
- end
20
+ ::String.send(:alias_method, :to_const_string, :camelcase)
21
+ ::String.send(:alias_method, :to_const_path, :underscore)
14
22
  end
15
23
 
16
24
  def version(default = "0")
@@ -1,3 +1,5 @@
1
+ require 'set'
2
+
1
3
  module Monkey
2
4
  module Ext
3
5
  module Array
@@ -9,6 +11,9 @@ module Monkey
9
11
  replace select(&block)
10
12
  end
11
13
 
14
+ def +@
15
+ Set.new self
16
+ end
12
17
  end
13
18
  end
14
19
  end
@@ -7,7 +7,6 @@ module Monkey
7
7
  expects :constantize, :to_const_string, :to_const_path, :underscore, :camelcase
8
8
 
9
9
  feature :version do
10
-
11
10
  def to_version
12
11
  dup.to_version!
13
12
  end
@@ -16,11 +15,9 @@ module Monkey
16
15
  extend Monkey::Version
17
16
  self
18
17
  end
19
-
20
18
  end
21
19
 
22
20
  feature :pathname do
23
-
24
21
  def atime
25
22
  Pathname(self).atime
26
23
  end
@@ -176,9 +173,7 @@ module Monkey
176
173
  def symlink?
177
174
  Pathname(self).symlink?
178
175
  end
179
-
180
176
  end
181
-
182
177
  end
183
178
  end
184
179
  end
@@ -0,0 +1,11 @@
1
+ module Monkey
2
+ module Ext
3
+ module Symbol
4
+ def ~@
5
+ Monkey::Matcher.new do |obj|
6
+ obj.respond_to?(self)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Monkey
2
+ class Matcher
3
+ def initialize(&block)
4
+ @block = block
5
+ end
6
+
7
+ def ===(other)
8
+ @block.call(other)
9
+ end
10
+ end
11
+ end
@@ -1,7 +1,6 @@
1
1
  require __FILE__.sub(%r{monkey/.*$}, "spec_helper")
2
2
 
3
3
  describe Monkey::Ext::Array do
4
-
5
4
  describe "backend expectations" do
6
5
  # expects :extract_options!
7
6
  it "imports extract_options! from backend" do
@@ -18,7 +17,6 @@ describe Monkey::Ext::Array do
18
17
  end
19
18
 
20
19
  describe "select!" do
21
-
22
20
  it "results in the same arrays as Array#select" do
23
21
  ([1, 2, 3, 4, 5, 6].select! { |e| e > 3 }).should == ([1, 2, 3, 4, 5, 6].select { |e| e > 3 })
24
22
  ([1, 2, 3, 4, 5, 6].select! { |e| e < 0 }).should == ([1, 2, 3, 4, 5, 6].select { |e| e < 0 })
@@ -29,7 +27,11 @@ describe Monkey::Ext::Array do
29
27
  x.select! { |e| e > 3 }
30
28
  x.should == [4, 5, 6]
31
29
  end
32
-
33
30
  end
34
31
 
32
+ describe '+@' do
33
+ it 'returns a set' do
34
+ (+[1,2]).should be_a(Set)
35
+ end
36
+ end
35
37
  end
@@ -0,0 +1,20 @@
1
+ require __FILE__.sub(%r{monkey/.*$}, "spec_helper")
2
+
3
+ describe Monkey::Ext::Symbol do
4
+ describe '~@' do
5
+ it 'should match objects responding to a method' do
6
+ matcher = ~:foo
7
+ o = Object.new
8
+ (matcher === o).should be_false
9
+ o.stub! :foo
10
+ (matcher === o).should be_true
11
+ end
12
+
13
+ it 'should work for case statements' do
14
+ case 'foo'
15
+ when ~:to_s then nil
16
+ else fail 'did not match'
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ require __FILE__.sub(%r{monkey/.*$}, "spec_helper")
2
+
3
+ describe Monkey::Matcher do
4
+ it 'should consider block for #===' do
5
+ matcher = Monkey::Matcher.new { |x| x > 6 }
6
+ (matcher === 5).should be_false
7
+ (matcher === 8).should be_true
8
+ end
9
+
10
+ it 'should work with switch' do
11
+ matcher = Monkey::Matcher.new { |x| /foo/ === x }
12
+ case 'foobar'
13
+ when matcher then nil
14
+ else fail 'did not match'
15
+ end
16
+ end
17
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monkey-lib
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 2
10
- version: 0.5.2
9
+ - 3
10
+ version: 0.5.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Konstantin Haase
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-18 00:00:00 +02:00
18
+ date: 2010-09-07 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -59,8 +59,10 @@ extra_rdoc_files:
59
59
  - lib/monkey/ext/object.rb
60
60
  - lib/monkey/ext/pathname.rb
61
61
  - lib/monkey/ext/string.rb
62
+ - lib/monkey/ext/symbol.rb
62
63
  - lib/monkey/ext.rb
63
64
  - lib/monkey/hash_fix.rb
65
+ - lib/monkey/matcher.rb
64
66
  - lib/monkey/version.rb
65
67
  - lib/monkey-lib.rb
66
68
  - lib/monkey.rb
@@ -86,8 +88,10 @@ files:
86
88
  - lib/monkey/ext/object.rb
87
89
  - lib/monkey/ext/pathname.rb
88
90
  - lib/monkey/ext/string.rb
91
+ - lib/monkey/ext/symbol.rb
89
92
  - lib/monkey/ext.rb
90
93
  - lib/monkey/hash_fix.rb
94
+ - lib/monkey/matcher.rb
91
95
  - lib/monkey/version.rb
92
96
  - lib/monkey-lib.rb
93
97
  - lib/monkey.rb
@@ -99,7 +103,9 @@ files:
99
103
  - spec/monkey/ext/object_spec.rb
100
104
  - spec/monkey/ext/pathname_spec.rb
101
105
  - spec/monkey/ext/string_spec.rb
106
+ - spec/monkey/ext/symbol_spec.rb
102
107
  - spec/monkey/ext_spec.rb
108
+ - spec/monkey/matcher_spec.rb
103
109
  - spec/monkey_spec.rb
104
110
  - spec/spec_helper.rb
105
111
  has_rdoc: true