uber 0.0.7 → 0.0.8
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.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/README.md +34 -0
- data/lib/uber/delegates.rb +13 -0
- data/lib/uber/uber_version.rb +1 -1
- data/test/delegates_test.rb +44 -0
- data/test/inheritance_test.rb +39 -42
- metadata +14 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0665bfd37394ce176ce0d33f2c1d1f55f32dfa70
|
4
|
+
data.tar.gz: 9a7bf2915ff6dd350d8d99c92c6a4b4afb9b6510
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5dc8ce07c0dc65cf1f818294f785f6c6bba0849a4ddf45152a379747ecbc3c981d895a6a6e9f0e8964eecd972234dc1838cbcb27b15f12f25bc12f44268dfbf
|
7
|
+
data.tar.gz: d2dec91003d742e658c4c53350430f3793d3cf2edd43f4ae7644aeb6e12e9cab68c584bbcc4c7b9352feb6e970789fc4ce1ff8699347bf20ed353d825d2c3990
|
data/CHANGES.md
CHANGED
data/README.md
CHANGED
@@ -156,6 +156,40 @@ Use `Options::Value#evaluate` to handle single values.
|
|
156
156
|
Evaluating an options hash can be time-consuming. When `Options` contains static elements only, it behaves *and performs* like an ordinary hash.
|
157
157
|
|
158
158
|
|
159
|
+
# Delegates
|
160
|
+
|
161
|
+
Using `::delegates` works exactly like the `Forwardable` module in Ruby, with one bonus: It creates the accessors in a module, allowing you to override and call `super` in a user module or class.
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
require 'uber/delegates'
|
165
|
+
|
166
|
+
class SongDecorator
|
167
|
+
def initialize(song)
|
168
|
+
@song = song
|
169
|
+
end
|
170
|
+
attr_reader :song
|
171
|
+
|
172
|
+
extend Uber::Delegates
|
173
|
+
|
174
|
+
delegates :song, :title, :id # delegate :title and :id to #song.
|
175
|
+
|
176
|
+
def title
|
177
|
+
super.downcase # this calls the original delegate #title.
|
178
|
+
end
|
179
|
+
end
|
180
|
+
```
|
181
|
+
|
182
|
+
This creates readers `#title` and `#id` which are delegated to `#song`.
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
song = SongDecorator.new(Song.create(id: 1, title: "HELLOWEEN!"))
|
186
|
+
|
187
|
+
song.id #=> 1
|
188
|
+
song.title #=> "helloween!"
|
189
|
+
```
|
190
|
+
|
191
|
+
Note how `#title` calls the original title and then downcases the string.
|
192
|
+
|
159
193
|
# Version
|
160
194
|
|
161
195
|
Writing gems against other gems often involves checking for versions and loading appropriate version strategies - e.g. _"is Rails >= 4.0?"_. Uber gives you `Version` for easy, semantic version deciders.
|
data/lib/uber/uber_version.rb
CHANGED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'uber/delegates'
|
3
|
+
|
4
|
+
class DelegatesTest < MiniTest::Spec
|
5
|
+
class Song
|
6
|
+
extend Uber::Delegates
|
7
|
+
|
8
|
+
delegates :model, :title
|
9
|
+
|
10
|
+
def model
|
11
|
+
Struct.new(:title).new("Helloween")
|
12
|
+
end
|
13
|
+
|
14
|
+
def title
|
15
|
+
super.downcase
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# allows overriding in class.
|
20
|
+
it { Song.new.title.must_equal "helloween" }
|
21
|
+
|
22
|
+
|
23
|
+
module Title
|
24
|
+
extend Uber::Delegates
|
25
|
+
|
26
|
+
delegates :model, :title, :id
|
27
|
+
end
|
28
|
+
|
29
|
+
class Album
|
30
|
+
include Title
|
31
|
+
|
32
|
+
def model
|
33
|
+
Struct.new(:title, :id).new("Helloween", 1)
|
34
|
+
end
|
35
|
+
|
36
|
+
def title
|
37
|
+
super.downcase
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# allows overriding in class inherited from module.
|
42
|
+
it { Album.new.title.must_equal "helloween" }
|
43
|
+
it { Album.new.id.must_equal 1 }
|
44
|
+
end
|
data/test/inheritance_test.rb
CHANGED
@@ -1,55 +1,52 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'uber/inheritable_included'
|
1
|
+
# require 'test_helper'
|
2
|
+
# require 'uber/inheritable_included'
|
3
3
|
|
4
|
-
module InheritIncludedTo
|
5
|
-
|
6
|
-
|
4
|
+
# module InheritIncludedTo
|
5
|
+
# def self.call(includer, proc)
|
6
|
+
# proc.call(includer) # das will ich eigentlich machen
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
# includer.class_eval do
|
9
|
+
# @block = proc
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
11
|
+
# def self.included(base) #
|
12
|
+
# InheritIncludedTo.call(base, instance_variable_get(:@block))
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
# end
|
17
17
|
|
18
|
-
class InheritanceTest < MiniTest::Spec
|
19
|
-
|
20
|
-
|
18
|
+
# class InheritanceTest < MiniTest::Spec
|
19
|
+
# module Feature
|
20
|
+
# #extend Uber::InheritedIncluded
|
21
21
|
|
22
|
-
|
22
|
+
# CODE_BLOCK = lambda { |base| base.class_eval { extend ClassMethods } } # i want that to be executed at every include
|
23
23
|
|
24
|
-
instance_exec do
|
25
|
-
@block = CODE_BLOCK # this would happen in inherited_included do .. end
|
26
|
-
end
|
27
24
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
25
|
+
# def self.included(includer) #
|
26
|
+
# # CODE_BLOCK.call(base)
|
27
|
+
# InheritIncludedTo.call(includer, CODE_BLOCK)
|
28
|
+
# end
|
32
29
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
# module ClassMethods
|
31
|
+
# def feature; end
|
32
|
+
# end
|
33
|
+
# end
|
37
34
|
|
38
|
-
|
39
|
-
|
35
|
+
# module Extension
|
36
|
+
# include Feature
|
40
37
|
|
41
|
-
|
42
|
-
|
38
|
+
# # TODO: test overriding ::included
|
39
|
+
# end
|
43
40
|
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
# module Client
|
42
|
+
# include Extension
|
43
|
+
# end
|
47
44
|
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
# module ExtendedClient
|
46
|
+
# include Client
|
47
|
+
# end
|
51
48
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
49
|
+
# it { Extension.must_respond_to :feature }
|
50
|
+
# it { Client.must_respond_to :feature }
|
51
|
+
# it { ExtendedClient.must_respond_to :feature }
|
52
|
+
# end
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.10.1
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.10.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 5.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 5.0.0
|
41
41
|
description: A gem-authoring framework.
|
@@ -45,7 +45,7 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
48
|
+
- ".gitignore"
|
49
49
|
- CHANGES.md
|
50
50
|
- Gemfile
|
51
51
|
- LICENSE
|
@@ -53,10 +53,12 @@ files:
|
|
53
53
|
- Rakefile
|
54
54
|
- lib/uber.rb
|
55
55
|
- lib/uber/callable.rb
|
56
|
+
- lib/uber/delegates.rb
|
56
57
|
- lib/uber/inheritable_attr.rb
|
57
58
|
- lib/uber/options.rb
|
58
59
|
- lib/uber/uber_version.rb
|
59
60
|
- lib/uber/version.rb
|
61
|
+
- test/delegates_test.rb
|
60
62
|
- test/inheritable_attr_test.rb
|
61
63
|
- test/inheritance_test.rb
|
62
64
|
- test/options_test.rb
|
@@ -74,25 +76,27 @@ require_paths:
|
|
74
76
|
- lib
|
75
77
|
required_ruby_version: !ruby/object:Gem::Requirement
|
76
78
|
requirements:
|
77
|
-
- -
|
79
|
+
- - ">="
|
78
80
|
- !ruby/object:Gem::Version
|
79
81
|
version: '0'
|
80
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
83
|
requirements:
|
82
|
-
- -
|
84
|
+
- - ">="
|
83
85
|
- !ruby/object:Gem::Version
|
84
86
|
version: '0'
|
85
87
|
requirements: []
|
86
88
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.2.
|
89
|
+
rubygems_version: 2.2.1
|
88
90
|
signing_key:
|
89
91
|
specification_version: 4
|
90
92
|
summary: Gem-authoring tools like class method inheritance in modules, dynamic options
|
91
93
|
and more.
|
92
94
|
test_files:
|
95
|
+
- test/delegates_test.rb
|
93
96
|
- test/inheritable_attr_test.rb
|
94
97
|
- test/inheritance_test.rb
|
95
98
|
- test/options_test.rb
|
96
99
|
- test/test_helper.rb
|
97
100
|
- test/version_test.rb
|
98
101
|
- test/zeugs.rb
|
102
|
+
has_rdoc:
|