sugar-high 0.6.1 → 0.6.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -21,6 +21,7 @@ h2. Sugar packs
21
21
  * array
22
22
  * blank
23
23
  * class_ext
24
+ * delegate (extracted from Active Support)
24
25
  * dsl
25
26
  * enumerable
26
27
  * file
@@ -82,6 +83,14 @@ Makes it easy to autoload multiple modules by standard folder-to-module mapping
82
83
 
83
84
  Note: This pack has recently been extracted into its own gem called *sweet_loader*
84
85
 
86
+ h3. Delegate
87
+
88
+ Extracted from Active Support core extensions:
89
+
90
+ See "Delegate":http://apidock.com/rails/Module/delegate
91
+
92
+ @activesupport/lib/active_support/core_ext/module/delegation.rb@
93
+
85
94
  h3. DSL
86
95
 
87
96
  by @stanislaw
data/Rakefile CHANGED
@@ -33,7 +33,7 @@ end
33
33
 
34
34
  task :default => :test
35
35
 
36
- require 'rake/rdoctask'
36
+ require 'rdoc/task'
37
37
  Rake::RDocTask.new do |rdoc|
38
38
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
39
39
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.6.2.1
@@ -4,7 +4,7 @@ require 'sugar-high/arguments'
4
4
  require 'sugar-high/array'
5
5
  require 'active_support/inflector'
6
6
 
7
- class Module
7
+ class Module
8
8
 
9
9
  # multi_alias name, :create => :new, :insert_into => [:inject_into, :update], :read => :X_content
10
10
  # :options => :after
@@ -26,7 +26,7 @@ class Hash #:nodoc:
26
26
  end
27
27
 
28
28
  class String
29
- if !"".respond_to? :blank
29
+ unless "".respond_to? :blank
30
30
  def blank?
31
31
  self !~ /\S/
32
32
  end
@@ -0,0 +1,40 @@
1
+ class Module
2
+ unless self.respond_to? :delegate
3
+ def delegate(*methods)
4
+ options = methods.pop
5
+ unless options.is_a?(Hash) && to = options[:to]
6
+ raise ArgumentError, "Delegation needs a target. Supply an options hash with a :to key as the last argument (e.g. delegate :hello, :to => :greeter)."
7
+ end
8
+
9
+ if options[:prefix] == true && options[:to].to_s =~ /^[^a-z_]/
10
+ raise ArgumentError, "Can only automatically set the delegation prefix when delegating to a method."
11
+ end
12
+
13
+ prefix = options[:prefix] && "#{options[:prefix] == true ? to : options[:prefix]}_" || ''
14
+
15
+ file, line = caller.first.split(':', 2)
16
+ line = line.to_i
17
+
18
+ methods.each do |method|
19
+ on_nil =
20
+ if options[:allow_nil]
21
+ 'return'
22
+ else
23
+ %(raise "#{self}##{prefix}#{method} delegated to #{to}.#{method}, but #{to} is nil: \#{self.inspect}")
24
+ end
25
+ # def customer_name(*args, &block)
26
+ module_eval %{
27
+ def #{prefix}#{method}(*args, &block)
28
+ #{to}.__send__(#{method.inspect}, *args, &block)
29
+ rescue NoMethodError
30
+ if #{to}.nil?
31
+ #{on_nil}
32
+ else
33
+ raise
34
+ end
35
+ end
36
+ }
37
+ end
38
+ end
39
+ end
40
+ end
@@ -10,13 +10,13 @@ class String
10
10
  type == :upper ? letters.map!(&:upcase) : letters
11
11
  end
12
12
 
13
- unless new.respond_to? :trim
13
+ unless "".respond_to? :trim
14
14
  def trim
15
15
  self.strip
16
16
  end
17
17
  end
18
18
 
19
- unless new.respond_to? :concats
19
+ unless "".respond_to? :concats
20
20
  def concats *args
21
21
  args.inject(self) do |res, arg|
22
22
  res << arg.to_s
@@ -0,0 +1,14 @@
1
+ class Module
2
+ def delegate
3
+ 7
4
+ end
5
+ end
6
+
7
+ require 'sugar-high/delegate'
8
+
9
+ class Context
10
+ end
11
+
12
+ describe 'delegate already defined' do
13
+ specify { Context.delegate.should == 7 }
14
+ end
@@ -0,0 +1,19 @@
1
+ require 'sugar-high/delegate'
2
+
3
+ class Actor
4
+ def act
5
+ 'actor'
6
+ end
7
+ end
8
+
9
+ class Context
10
+ delegate :act, :to => :actor
11
+
12
+ def actor
13
+ Actor.new
14
+ end
15
+ end
16
+
17
+ describe 'delegate NOT already defined' do
18
+ specify { Context.new.act.should == 'actor' }
19
+ end
data/sugar-high.gemspec CHANGED
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = "sugar-high"
8
- s.version = "0.6.1"
7
+ s.name = %q{sugar-high}
8
+ s.version = "0.6.2.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Kristian Mandrup"]
12
- s.date = "2011-12-06"
13
- s.description = "More Ruby sugar - inspired by the 'zuker' project"
14
- s.email = "kmandrup@gmail.com"
11
+ s.authors = [%q{Kristian Mandrup}]
12
+ s.date = %q{2011-12-06}
13
+ s.description = %q{More Ruby sugar - inspired by the 'zuker' project}
14
+ s.email = %q{kmandrup@gmail.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.textile"
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
31
31
  "lib/sugar-high/blank.rb",
32
32
  "lib/sugar-high/boolean.rb",
33
33
  "lib/sugar-high/class_ext.rb",
34
+ "lib/sugar-high/delegate.rb",
34
35
  "lib/sugar-high/dsl.rb",
35
36
  "lib/sugar-high/enumerable.rb",
36
37
  "lib/sugar-high/file.rb",
@@ -59,6 +60,8 @@ Gem::Specification.new do |s|
59
60
  "spec/sugar-high/arguments_spec.rb",
60
61
  "spec/sugar-high/array_spec.rb",
61
62
  "spec/sugar-high/blank_spec.rb",
63
+ "spec/sugar-high/delegate_defined_spec.rb",
64
+ "spec/sugar-high/delegate_spec.rb",
62
65
  "spec/sugar-high/dsl_spec.rb",
63
66
  "spec/sugar-high/file_spec.rb",
64
67
  "spec/sugar-high/hash_spec.rb",
@@ -78,10 +81,10 @@ Gem::Specification.new do |s|
78
81
  "spec/sugar-high/string_spec.rb",
79
82
  "sugar-high.gemspec"
80
83
  ]
81
- s.homepage = "http://github.com/kristianmandrup/sugar-high"
82
- s.require_paths = ["lib"]
83
- s.rubygems_version = "1.8.10"
84
- s.summary = "Ruby convenience sugar packs!"
84
+ s.homepage = %q{http://github.com/kristianmandrup/sugar-high}
85
+ s.require_paths = [%q{lib}]
86
+ s.rubygems_version = %q{1.8.6}
87
+ s.summary = %q{Ruby convenience sugar packs!}
85
88
 
86
89
  if s.respond_to? :specification_version then
87
90
  s.specification_version = 3
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.6.1
4
+ version: 0.6.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-12-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &899493810 !ruby/object:Gem::Requirement
16
+ requirement: &70274944833600 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.0.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *899493810
24
+ version_requirements: *70274944833600
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &899450620 !ruby/object:Gem::Requirement
27
+ requirement: &70274944832940 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.4.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *899450620
35
+ version_requirements: *70274944832940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rails
38
- requirement: &899449950 !ruby/object:Gem::Requirement
38
+ requirement: &70274944832340 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 3.0.1
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *899449950
46
+ version_requirements: *70274944832340
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &899449180 !ruby/object:Gem::Requirement
49
+ requirement: &70274944831760 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *899449180
57
+ version_requirements: *70274944831760
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bundler
60
- requirement: &899448420 !ruby/object:Gem::Requirement
60
+ requirement: &70274944831000 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.0.1
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *899448420
68
+ version_requirements: *70274944831000
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
- requirement: &899447800 !ruby/object:Gem::Requirement
71
+ requirement: &70274944830140 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *899447800
79
+ version_requirements: *70274944830140
80
80
  description: More Ruby sugar - inspired by the 'zuker' project
81
81
  email: kmandrup@gmail.com
82
82
  executables: []
@@ -99,6 +99,7 @@ files:
99
99
  - lib/sugar-high/blank.rb
100
100
  - lib/sugar-high/boolean.rb
101
101
  - lib/sugar-high/class_ext.rb
102
+ - lib/sugar-high/delegate.rb
102
103
  - lib/sugar-high/dsl.rb
103
104
  - lib/sugar-high/enumerable.rb
104
105
  - lib/sugar-high/file.rb
@@ -127,6 +128,8 @@ files:
127
128
  - spec/sugar-high/arguments_spec.rb
128
129
  - spec/sugar-high/array_spec.rb
129
130
  - spec/sugar-high/blank_spec.rb
131
+ - spec/sugar-high/delegate_defined_spec.rb
132
+ - spec/sugar-high/delegate_spec.rb
130
133
  - spec/sugar-high/dsl_spec.rb
131
134
  - spec/sugar-high/file_spec.rb
132
135
  - spec/sugar-high/hash_spec.rb
@@ -159,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
162
  version: '0'
160
163
  segments:
161
164
  - 0
162
- hash: 595246579
165
+ hash: 2216791664347313747
163
166
  required_rubygems_version: !ruby/object:Gem::Requirement
164
167
  none: false
165
168
  requirements:
@@ -168,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
171
  version: '0'
169
172
  requirements: []
170
173
  rubyforge_project:
171
- rubygems_version: 1.8.10
174
+ rubygems_version: 1.8.6
172
175
  signing_key:
173
176
  specification_version: 3
174
177
  summary: Ruby convenience sugar packs!