sugar-high 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -41,11 +41,21 @@ end
41
41
 
42
42
  # http://blog.jayfields.com/2008/02/ruby-replace-methodmissing-with-dynamic.html
43
43
  class DelegateDecorator
44
- def initialize(subject)
45
- subject.public_methods(false).each do |meth|
44
+ def initialize(subject, options = {})
45
+ options[:only] ||= []
46
+ options[:except] ||= []
47
+ options[:only].map!(&:to_s)
48
+ options[:except].map!(&:to_s)
49
+
50
+ meths = subject.public_methods(false)
51
+ meths = meths & options[:only] unless options[:only].empty?
52
+
53
+ meths.each do |meth|
46
54
  (class << self; self; end).class_eval do
47
- define_method meth do |*args|
48
- subject.send meth, *args
55
+ unless options[:except].include? meth.to_s
56
+ define_method meth do |*args|
57
+ subject.send meth, *args
58
+ end
49
59
  end
50
60
  end
51
61
  end
@@ -1,3 +1,3 @@
1
1
  module SugarHigh
2
- VERSION = '0.7.2'
2
+ VERSION = '0.7.3'
3
3
  end
@@ -17,3 +17,32 @@ end
17
17
  describe 'delegate NOT already defined' do
18
18
  specify { Context.new.act.should == 'actor' }
19
19
  end
20
+
21
+ class SuperRange < DelegateDecorator
22
+ attr_accessor :range
23
+
24
+ def initialize range
25
+ super(range, except: ['to_s', 'to_str'])
26
+ @range = range
27
+ end
28
+
29
+ def to_s
30
+ "Super: #{range}"
31
+ end
32
+
33
+ def to_str
34
+ to_s
35
+ end
36
+ end
37
+
38
+ describe DelegateDecorator do
39
+ subject { SuperRange.new (0..2) }
40
+
41
+ specify {
42
+ subject.to_s.should == "Super: 0..2"
43
+ subject.to_str.should == "Super: 0..2"
44
+ }
45
+
46
+ specify { subject.min.should == subject.range.min }
47
+ specify { subject.max.should == subject.range.max }
48
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "sugar-high"
8
- s.version = "0.7.2"
8
+ s.version = "0.7.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
12
- s.date = "2012-09-25"
12
+ s.date = "2012-10-18"
13
13
  s.description = "More Ruby sugar - inspired by the 'zuker' project"
14
14
  s.email = "kmandrup@gmail.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugar-high
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.7.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-25 00:00:00.000000000 Z
12
+ date: 2012-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -180,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
180
  version: '0'
181
181
  segments:
182
182
  - 0
183
- hash: -2985088833944067172
183
+ hash: 2672001134034740411
184
184
  required_rubygems_version: !ruby/object:Gem::Requirement
185
185
  none: false
186
186
  requirements: