direction 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 727eb9585c633d12cc9995c9c73cc524eeba82ff
4
- data.tar.gz: d069923519bf447766d13afbe2ab621137d229b4
3
+ metadata.gz: 7d48a28fa9687fe3184d4e74550a3fe16e7527d1
4
+ data.tar.gz: 0eb918bffd66cb1c71e01c604604e3587e47b709
5
5
  SHA512:
6
- metadata.gz: c5e95f10ed99d01e632041d81d2157da594d5c46c8f3a85895b1ce70e47119345b66b77d29cd846582ae4c4b9bbe00b4766e7ebf21996bfbfb38e0ce58cfad8c
7
- data.tar.gz: b84abee5835f01a005bfc615585e3bb71ba454088b012a63eac26a4f539c7afd7a907eb80e12ff0e6df96b506649e8663679868def45d6ce2902fec3931fd527
6
+ metadata.gz: 32429be8418ce8845ef14a76e8df0cdea5c02941a74de6a93f63173da6d9210612b28c637cfe42256659370c1ad70e4e238412ddf9858c97077cdfafcfb53483
7
+ data.tar.gz: ef69f8fa1f87d5dc652ee4757b3467a41e96efc00980dfa4f8cbe25eb4d5131fe226ef2831c1cc846631a9b574855cb79aba77b37be5e66f23b7c26b940e15de
data/.travis.yml ADDED
@@ -0,0 +1,11 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ - ruby-head
5
+ - jruby-head
6
+ - rbx-2
7
+ env:
8
+ - COVERALLS=true
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: jruby-head
data/Gemfile CHANGED
@@ -1,4 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in direction.gemspec
4
3
  gemspec
4
+
5
+ group :test do
6
+ gem 'rubinius-coverage', platform: :rbx
7
+ gem 'coveralls', require: false
8
+ gem 'minitest'
9
+ gem 'rake'
10
+ gem 'simplecov'
11
+ end
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
@@ -1,3 +1,3 @@
1
1
  module Direction
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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
- method_defs = []
20
- options.each_pair do |key, value|
21
- Array(key).map do |command_name|
22
- method_defs.unshift %{
23
- def #{command_name}(*args, &block)
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 |key, value|
36
- Array(key).map do |command_name|
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
- self.class_eval method_defs.join(' '), __FILE__, __LINE__
49
+ mod.class_eval method_defs.join("\n"), __FILE__, __LINE__
45
50
  end
46
51
  end
@@ -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
@@ -1,3 +1,12 @@
1
- require 'minitest/spec'
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter 'test'
4
+ end
5
+
6
+ require 'coveralls'
7
+ if ENV['COVERALLS']
8
+ Coveralls.wear!
9
+ end
10
+
2
11
  require 'minitest/autorun'
3
12
  require 'direction'
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.3
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-08-15 00:00:00.000000000 Z
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.0
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.