bondo 0.0.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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +3 -0
- data.tar.gz.sig +2 -0
- data/README.md +78 -0
- data/Rakefile +5 -0
- data/lib/bondo.rb +61 -0
- data/lib/bondo/version.rb +3 -0
- data/test/test.rb +56 -0
- metadata +86 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 74e00df0311f04729fd99082d4f4ecc742fd93e0
|
4
|
+
data.tar.gz: e2643b731c8e116c8e246931642253b08aa0d48c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0d659a9d7b0639086245386c9a38f58c1eb72581ce3f9eb59753ff21dc1f9dec9414d611414e18628a6b18deb8a97eb6dcb6dbd1fceca51a780251e3e2155475
|
7
|
+
data.tar.gz: b718836fae405446e5218eecfc4922879bbde5069a6f7bafc9ce99840c735af097f3ae5dc1e93c36f5bc9f97b543c03a800d21634d7051ca966292275082277d
|
checksums.yaml.gz.sig
ADDED
data.tar.gz.sig
ADDED
data/README.md
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
[](https://travis-ci.org/steakknife/bondo)
|
2
|
+
|
3
|
+
# Bondo
|
4
|
+
|
5
|
+
### Deterministic Ruby multi-object "inheritance" (composition) spackle
|
6
|
+
|
7
|
+
## Advantages
|
8
|
+
|
9
|
+
- Dries in minutes
|
10
|
+
- Easy cleanup
|
11
|
+
- Add & remove instance methods of an individual object instance... on-the-fly
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
gem cert --add <(curl -L https://raw.githubusercontent.com/steakknife/bondo/master/gem-public_cert.pem)
|
16
|
+
gem install bondo -P HighSecurity
|
17
|
+
|
18
|
+
## Notes
|
19
|
+
|
20
|
+
### Conflict-resolution behavior
|
21
|
+
|
22
|
+
#### Default
|
23
|
+
|
24
|
+
Last added bondo child object wins (gets called)
|
25
|
+
|
26
|
+
#### Custom
|
27
|
+
|
28
|
+
# call all, first added order
|
29
|
+
def foo
|
30
|
+
bondo_children.reverse.map { |x| x.foo(*args, &block) }
|
31
|
+
end
|
32
|
+
|
33
|
+
# call all, last added order
|
34
|
+
def foo(*args, &block)
|
35
|
+
bondo_children.map { |x| x.foo(*args, &block) }
|
36
|
+
end
|
37
|
+
|
38
|
+
# call child 0 and child 3
|
39
|
+
def foo(*args, &block)
|
40
|
+
[ bondo_children[0].foo(*args, &block),
|
41
|
+
bondo_children[3].foo(*args, &block) ]
|
42
|
+
end
|
43
|
+
|
44
|
+
## Usage
|
45
|
+
|
46
|
+
require 'bondo'
|
47
|
+
|
48
|
+
class Bar
|
49
|
+
def start
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Baz
|
54
|
+
def eject
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class Foo < SomeClass
|
59
|
+
include Bondo
|
60
|
+
|
61
|
+
def initialize
|
62
|
+
bondo_add Bar.new
|
63
|
+
bondo_add Baz.new
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
f = Foo.new
|
68
|
+
f.stop
|
69
|
+
f.eject
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
MIT
|
74
|
+
|
75
|
+
## Copyright
|
76
|
+
|
77
|
+
Copyright 2014 Barry Allard
|
78
|
+
|
data/Rakefile
ADDED
data/lib/bondo.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Usage
|
2
|
+
#
|
3
|
+
# require 'bondo'
|
4
|
+
#
|
5
|
+
# class Bar
|
6
|
+
# def start
|
7
|
+
# end
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# class Baz
|
11
|
+
# def eject
|
12
|
+
# end
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# class Foo < SomeClass
|
16
|
+
# include Bondo
|
17
|
+
#
|
18
|
+
# def initialize
|
19
|
+
# bondo_add Bar.new
|
20
|
+
# bondo_add Baz.new
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
# f = Foo.new
|
25
|
+
# f.stop
|
26
|
+
# f.eject
|
27
|
+
#
|
28
|
+
module Bondo
|
29
|
+
def bondo_children
|
30
|
+
@bondo_children ||= []
|
31
|
+
end
|
32
|
+
|
33
|
+
def bondo_add(*children)
|
34
|
+
children.each { |child| bondo_children.unshift child } unless bondo_has_all?(*children)
|
35
|
+
end
|
36
|
+
|
37
|
+
def bondo_has_all?(*children)
|
38
|
+
children.all? { |child| bondo_has? child }
|
39
|
+
end
|
40
|
+
|
41
|
+
def bondo_has?(child)
|
42
|
+
bondo_children.include? child
|
43
|
+
end
|
44
|
+
|
45
|
+
def bondo_remove(child)
|
46
|
+
bondo_children.delete child if bondo_has? child
|
47
|
+
end
|
48
|
+
|
49
|
+
def respond_to_missing?(symbol_or_string, include_all)
|
50
|
+
bondo_children.map { |x| x.respond_to? symbol_or_string, include_all }.any? || super
|
51
|
+
end
|
52
|
+
|
53
|
+
def method_missing(symbol_or_string, *args, &block)
|
54
|
+
if respond_to_missing?(symbol_or_string, false)
|
55
|
+
bondo_children.map { |x|
|
56
|
+
return x.send(symbol_or_string, *args, &block) if x.respond_to? symbol_or_string
|
57
|
+
}
|
58
|
+
end
|
59
|
+
super
|
60
|
+
end
|
61
|
+
end
|
data/test/test.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << 'lib'
|
3
|
+
require 'bondo'
|
4
|
+
|
5
|
+
class Foo
|
6
|
+
def f
|
7
|
+
$f = 1
|
8
|
+
end
|
9
|
+
|
10
|
+
def x
|
11
|
+
fail 'Foo.x should NOT have been called'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Bar
|
16
|
+
def g
|
17
|
+
$g = 1
|
18
|
+
end
|
19
|
+
|
20
|
+
def x
|
21
|
+
$x = true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Composite
|
26
|
+
include Bondo
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
bondo_add Foo.new
|
30
|
+
bondo_add Bar.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
x = Composite.new
|
35
|
+
|
36
|
+
# test 0
|
37
|
+
x.f
|
38
|
+
fail 'f failed' unless $f
|
39
|
+
|
40
|
+
# test 1
|
41
|
+
x.g
|
42
|
+
fail 'g failed' unless $g
|
43
|
+
|
44
|
+
# test 2
|
45
|
+
begin
|
46
|
+
x.h
|
47
|
+
rescue NoMethodError
|
48
|
+
else
|
49
|
+
fail 'h should not work'
|
50
|
+
end
|
51
|
+
|
52
|
+
# test 3
|
53
|
+
x.x
|
54
|
+
fail 'Bar.x should have been called' unless $x
|
55
|
+
|
56
|
+
$stderr.puts 'ok'
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bondo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Barry Allard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDOjCCAiKgAwIBAgIBADANBgkqhkiG9w0BAQUFADBDMRUwEwYDVQQDDAxiYXJy
|
14
|
+
eS5hbGxhcmQxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkW
|
15
|
+
A2NvbTAeFw0xMzA0MDgwMTI0NThaFw0xNDA0MDgwMTI0NThaMEMxFTATBgNVBAMM
|
16
|
+
DGJhcnJ5LmFsbGFyZDEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPy
|
17
|
+
LGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvDcmlxJH
|
18
|
+
eySiUBcYTqGXaWETRVYmgfGwWRPZzqkmBdIVZkbk9SWxseiHWIReFWjP438UoUTs
|
19
|
+
J17G/HuQb0SmjPCMZy8967Fb2wqs+QRbcmpnmtYA1vilgC2CIzntFOFLSA2KpfZH
|
20
|
+
dJSsg6aaXqwS4/KJxK6ooDsp+iR6zGTINwkdUt4ktpqgCHz1VYuzvii2slnazbm4
|
21
|
+
cQUi/wWIynHyzzdrPvDhGgaZm161MYHidCtV+wzqwjeVeFsyQwCFVEkrD/0G98ho
|
22
|
+
Gti8vB6Xj6VjO3n+kh/KlYZgmM7SWauLpo+2RGlIYVYdpQQWGwhMEmvSgBxjfX4c
|
23
|
+
unDFxO1ZAQIRBQIDAQABozkwNzAJBgNVHRMEAjAAMB0GA1UdDgQWBBS+Kk7ypi9u
|
24
|
+
kFUcaqJlpaKO7eWiUTALBgNVHQ8EBAMCBLAwDQYJKoZIhvcNAQEFBQADggEBALie
|
25
|
+
YCNeW9EIQ/j8+2emMm0484JVtycOqPyIu5UALtsU42En392HVOZ6oEA/rh2KFRvq
|
26
|
+
dcDwcJPI/u7PzWp9TNp81PTShtHMtSs7Wv1UsC04vQ9b6XBEomWbbzoxxgzyjP7l
|
27
|
+
ZV4L5HzmX0nDOSEFJyYkqbwgYjIoldg2TMlw2BeoVqGm7Gx1ljXKb2Kg5iasyDpI
|
28
|
+
C/gAiGBIAX7FxyIXmjZq38xWBOxyGF3NFL/W6z+vhJg81HGdNBCpIdwrQ/eXOjba
|
29
|
+
VqwwfY+Ms3gcCHSERG1X4AFW1zesX+UWcTCwVLtAsuRWQhC8odDSVDWzUfkZmOQt
|
30
|
+
ViIxU1ZphInql7L5g34=
|
31
|
+
-----END CERTIFICATE-----
|
32
|
+
date: 2014-04-04 00:00:00.000000000 Z
|
33
|
+
dependencies:
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rake
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
description: Sensible composite Ruby objects
|
49
|
+
email:
|
50
|
+
- barry.allard@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- lib/bondo.rb
|
58
|
+
- lib/bondo/version.rb
|
59
|
+
- test/test.rb
|
60
|
+
homepage: https://github.com/steakknife/bondo
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.2.2
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Deterministic, composite Ruby objects
|
84
|
+
test_files:
|
85
|
+
- test/test.rb
|
86
|
+
has_rdoc:
|
metadata.gz.sig
ADDED
Binary file
|