direction 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +11 -0
- data/Gemfile +8 -1
- data/README.md +2 -0
- data/direction.gemspec +0 -3
- data/lib/direction/version.rb +1 -1
- data/lib/direction.rb +23 -18
- data/test/direction_test.rb +27 -2
- data/test/sample.rb +4 -1
- data/test/test_helper.rb +10 -1
- metadata +5 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d48a28fa9687fe3184d4e74550a3fe16e7527d1
|
4
|
+
data.tar.gz: 0eb918bffd66cb1c71e01c604604e3587e47b709
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32429be8418ce8845ef14a76e8df0cdea5c02941a74de6a93f63173da6d9210612b28c637cfe42256659370c1ad70e4e238412ddf9858c97077cdfafcfb53483
|
7
|
+
data.tar.gz: ef69f8fa1f87d5dc652ee4757b3467a41e96efc00980dfa4f8cbe25eb4d5131fe226ef2831c1cc846631a9b574855cb79aba77b37be5e66f23b7c26b940e15de
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -52,6 +52,8 @@ Or install it yourself as:
|
|
52
52
|
|
53
53
|
## Contributing
|
54
54
|
|
55
|
+
Special thanks to [Aaron Kromer](https://github.com/cupakromer/) and [Ken Collins](https://github.com/metaskills) for their thoughts and code.
|
56
|
+
|
55
57
|
1. Fork it ( http://github.com/saturnflyer/direction/fork )
|
56
58
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
57
59
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
data/direction.gemspec
CHANGED
@@ -17,7 +17,4 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
-
spec.add_development_dependency "rake"
|
23
20
|
end
|
data/lib/direction/version.rb
CHANGED
data/lib/direction.rb
CHANGED
@@ -15,32 +15,37 @@ require "direction/version"
|
|
15
15
|
# provided receiver while enforcing encapsulation of the
|
16
16
|
# relationship between objects.
|
17
17
|
module Direction
|
18
|
+
|
19
|
+
# Forward messages and return self, protecting the encapsulation of the object
|
18
20
|
def command(options)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
#{value}.__send__(:#{command_name}, *args, &block)
|
25
|
-
self
|
26
|
-
end
|
27
|
-
}
|
21
|
+
Direction.define_methods(self, options) do |message, accessor|
|
22
|
+
%{
|
23
|
+
def #{message}(*args, &block)
|
24
|
+
#{accessor}.__send__(:#{message}, *args, &block)
|
25
|
+
self
|
28
26
|
end
|
27
|
+
}
|
29
28
|
end
|
30
|
-
self.class_eval method_defs.join(' '), __FILE__, __LINE__
|
31
29
|
end
|
32
30
|
|
31
|
+
# Forward messages and return the result of the forwarded message
|
33
32
|
def query(options)
|
33
|
+
Direction.define_methods(self, options) do |message, accessor|
|
34
|
+
%{
|
35
|
+
def #{message}(*args, &block)
|
36
|
+
#{accessor}.__send__(:#{message}, *args, &block)
|
37
|
+
end
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.define_methods(mod, options)
|
34
43
|
method_defs = []
|
35
|
-
options.each_pair do |
|
36
|
-
Array(
|
37
|
-
method_defs.unshift
|
38
|
-
def #{command_name}(*args, &block)
|
39
|
-
#{value}.__send__(:#{command_name}, *args, &block)
|
40
|
-
end
|
41
|
-
}
|
44
|
+
options.each_pair do |method_names, accessor|
|
45
|
+
Array(method_names).map do |message|
|
46
|
+
method_defs.unshift yield(message, accessor)
|
42
47
|
end
|
43
48
|
end
|
44
|
-
|
49
|
+
mod.class_eval method_defs.join("\n"), __FILE__, __LINE__
|
45
50
|
end
|
46
51
|
end
|
data/test/direction_test.rb
CHANGED
@@ -2,8 +2,8 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class Person
|
4
4
|
extend Direction
|
5
|
-
command [:make_me_a_sandwich, :cook] => :@friend
|
6
|
-
query [:activities, :go] => :friend
|
5
|
+
command [:make_me_a_sandwich, :cook, :blocky] => :@friend
|
6
|
+
query [:activities, :go, :say_what] => :friend
|
7
7
|
attr_accessor :friend
|
8
8
|
end
|
9
9
|
|
@@ -23,6 +23,14 @@ class Friend
|
|
23
23
|
def go(do_what)
|
24
24
|
Activities.record do_what
|
25
25
|
end
|
26
|
+
|
27
|
+
def blocky(text)
|
28
|
+
Activities.record([yield(self).to_s,text].join(' '))
|
29
|
+
end
|
30
|
+
|
31
|
+
def say_what(text)
|
32
|
+
[yield(self).to_s,text].join(' ')
|
33
|
+
end
|
26
34
|
end
|
27
35
|
|
28
36
|
module Menu
|
@@ -57,6 +65,7 @@ describe Direction, 'command' do
|
|
57
65
|
}
|
58
66
|
before do
|
59
67
|
Menu.clear
|
68
|
+
Activities.clear
|
60
69
|
end
|
61
70
|
it 'forwards a message to another object' do
|
62
71
|
assert_equal [], Menu.list
|
@@ -73,6 +82,14 @@ describe Direction, 'command' do
|
|
73
82
|
person.cook('yum')
|
74
83
|
assert_includes Menu.list, "yum"
|
75
84
|
end
|
85
|
+
|
86
|
+
it 'forwards block arguments' do
|
87
|
+
assert_equal [], Activities.list
|
88
|
+
person.blocky('yay!') do |friend|
|
89
|
+
"Arguments forwarded to #{friend}"
|
90
|
+
end
|
91
|
+
assert_includes Activities.list, "Arguments forwarded to #{friend} yay!"
|
92
|
+
end
|
76
93
|
end
|
77
94
|
|
78
95
|
describe Direction, 'query' do
|
@@ -94,4 +111,12 @@ describe Direction, 'query' do
|
|
94
111
|
person.go('have fun')
|
95
112
|
assert_includes Activities.list, "have fun"
|
96
113
|
end
|
114
|
+
|
115
|
+
it 'forwards block arguments' do
|
116
|
+
assert_equal [], Activities.list
|
117
|
+
what_said = person.say_what('yay!') do |friend|
|
118
|
+
"Arguments forwarded to #{friend}"
|
119
|
+
end
|
120
|
+
assert_equal what_said, "Arguments forwarded to #{friend} yay!"
|
121
|
+
end
|
97
122
|
end
|
data/test/sample.rb
CHANGED
@@ -80,4 +80,7 @@ def setup
|
|
80
80
|
@manager = MicroManager.new(@server)
|
81
81
|
@customer = Customer.new(@server)
|
82
82
|
@manager
|
83
|
-
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Try loading this in the console and interact to make food using @manager vs. @customer
|
86
|
+
# @customer.order_food('burrito').pay_bill vs. ... lots of commands for @manager
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: direction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "'Jim Gay'"
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.5'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.5'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
11
|
+
date: 2014-10-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
41
13
|
description: Forward messages to collaborators in East-oriented style.
|
42
14
|
email:
|
43
15
|
- jim@saturnflyer.com
|
@@ -46,6 +18,7 @@ extensions: []
|
|
46
18
|
extra_rdoc_files: []
|
47
19
|
files:
|
48
20
|
- ".gitignore"
|
21
|
+
- ".travis.yml"
|
49
22
|
- Gemfile
|
50
23
|
- LICENSE.txt
|
51
24
|
- README.md
|
@@ -76,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
49
|
version: '0'
|
77
50
|
requirements: []
|
78
51
|
rubyforge_project:
|
79
|
-
rubygems_version: 2.2.
|
52
|
+
rubygems_version: 2.2.2
|
80
53
|
signing_key:
|
81
54
|
specification_version: 4
|
82
55
|
summary: Forward messages to collaborators in East-oriented style.
|