direction 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d48a28fa9687fe3184d4e74550a3fe16e7527d1
4
- data.tar.gz: 0eb918bffd66cb1c71e01c604604e3587e47b709
3
+ metadata.gz: 70ef36550c39745b1259e2f37ce744e0a084ce59
4
+ data.tar.gz: 923ffca99a808f99a6032a773b0fa8552823e0bc
5
5
  SHA512:
6
- metadata.gz: 32429be8418ce8845ef14a76e8df0cdea5c02941a74de6a93f63173da6d9210612b28c637cfe42256659370c1ad70e4e238412ddf9858c97077cdfafcfb53483
7
- data.tar.gz: ef69f8fa1f87d5dc652ee4757b3467a41e96efc00980dfa4f8cbe25eb4d5131fe226ef2831c1cc846631a9b574855cb79aba77b37be5e66f23b7c26b940e15de
6
+ metadata.gz: e1ecae8e58ff1e234052b3768b49b8fe5db442c94efd9e55c6a0eacd80bd51fbd441819516c9daa450eac86b897295ee1b15b07b051034be21aafa727174022d
7
+ data.tar.gz: 8d18a5b422438f796853401efbbf35dcf8e3ff9289628a0b6b1b71c65cbf2d1b79fa2aa9b29f83882761b7739f5813e74834b9241d4f352f364d796a3cee7f23
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Direction
2
2
 
3
+ [![Build Status](https://travis-ci.org/saturnflyer/direction.png?branch=master)](https://travis-ci.org/saturnflyer/direction)
4
+ [![Code Climate](https://codeclimate.com/github/saturnflyer/direction.png)](https://codeclimate.com/github/saturnflyer/direction)
5
+ [![Coverage Status](https://coveralls.io/repos/saturnflyer/direction/badge.png)](https://coveralls.io/r/saturnflyer/direction)
6
+ [![Gem Version](https://badge.fury.io/rb/direction.png)](http://badge.fury.io/rb/direction)
7
+
3
8
  Enforce better encapsulation by returning self from commands.
4
9
 
5
10
  Thanks to James Ladd for the inspiration.
@@ -10,11 +10,10 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["jim@saturnflyer.com"]
11
11
  spec.summary = %q{Forward messages to collaborators in East-oriented style.}
12
12
  spec.description = %q{Forward messages to collaborators in East-oriented style.}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/saturnflyer/direction"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.files = [".gitignore", ".travis.yml", "Gemfile", "LICENSE.txt", "README.md", "Rakefile", "direction.gemspec", "lib/direction.rb", "lib/direction/version.rb", "sample.rb", "sample/accountant.rb", "sample/customer.rb", "sample/kitchen.rb", "sample/micro_manager.rb", "sample/server.rb", "test/direction_test.rb", "test/test_helper.rb"]
17
+ spec.test_files = ["test/direction_test.rb", "test/test_helper.rb"]
19
18
  spec.require_paths = ["lib"]
20
19
  end
@@ -18,10 +18,10 @@ module Direction
18
18
 
19
19
  # Forward messages and return self, protecting the encapsulation of the object
20
20
  def command(options)
21
- Direction.define_methods(self, options) do |message, accessor|
21
+ Direction.define_methods(self, options) do |command, accessor|
22
22
  %{
23
- def #{message}(*args, &block)
24
- #{accessor}.__send__(:#{message}, *args, &block)
23
+ def #{command}(*args, &block)
24
+ #{accessor}.__send__(:#{command}, *args, &block)
25
25
  self
26
26
  end
27
27
  }
@@ -30,10 +30,10 @@ module Direction
30
30
 
31
31
  # Forward messages and return the result of the forwarded message
32
32
  def query(options)
33
- Direction.define_methods(self, options) do |message, accessor|
33
+ Direction.define_methods(self, options) do |query, accessor|
34
34
  %{
35
- def #{message}(*args, &block)
36
- #{accessor}.__send__(:#{message}, *args, &block)
35
+ def #{query}(*args, &block)
36
+ #{accessor}.__send__(:#{query}, *args, &block)
37
37
  end
38
38
  }
39
39
  end
@@ -43,7 +43,7 @@ module Direction
43
43
  method_defs = []
44
44
  options.each_pair do |method_names, accessor|
45
45
  Array(method_names).map do |message|
46
- method_defs.unshift yield(message, accessor)
46
+ method_defs.push yield(message, accessor)
47
47
  end
48
48
  end
49
49
  mod.class_eval method_defs.join("\n"), __FILE__, __LINE__
@@ -1,3 +1,3 @@
1
1
  module Direction
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,27 @@
1
+ require 'direction'
2
+ $:.unshift(__dir__) unless $:.include?(__dir__)
3
+ require 'sample/accountant'
4
+ require 'sample/customer'
5
+ require 'sample/kitchen'
6
+ require 'sample/micro_manager'
7
+ require 'sample/server'
8
+
9
+ def setup
10
+ @kitchen = Kitchen.new
11
+ @server = Server.new(@kitchen)
12
+ @manager = MicroManager.new(@server)
13
+ @customer = Customer.new(@server)
14
+ @manager
15
+ self
16
+ end
17
+
18
+ def manager
19
+ @manager
20
+ end
21
+
22
+ def customer
23
+ @customer
24
+ end
25
+
26
+ # Try loading this in the console and interact to make food using @manager vs. @customer
27
+ # customer.order_food('burrito').pay_bill vs. ... lots of commands for @manager
@@ -0,0 +1,5 @@
1
+ class Accountant
2
+ def accept_funds
3
+ puts " $$$ Cha-ching!"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ class Customer
2
+ extend Direction
3
+ def initialize(server)
4
+ @server = server
5
+ end
6
+ attr_accessor :server
7
+
8
+ command [:order_food, :pay_bill] => :server
9
+ end
@@ -0,0 +1,15 @@
1
+ class Kitchen
2
+ def make_food(food)
3
+ puts " <Kitchen preparing #{food}>"
4
+ sleep(3)
5
+ puts " <Kitchen made #{food}>"
6
+ end
7
+
8
+ def provide_food(food)
9
+ puts " <Kitchen served up #{food}>"
10
+ end
11
+
12
+ def accountant
13
+ @accountant ||= Accountant.new
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ class MicroManager
2
+ def initialize(server)
3
+ @server = server
4
+ end
5
+ attr_accessor :server
6
+ end
@@ -0,0 +1,34 @@
1
+ class Server
2
+ def initialize(kitchen)
3
+ @kitchen = kitchen
4
+ @accountant = kitchen.accountant
5
+ end
6
+ attr_reader :kitchen
7
+ attr_accessor :customer
8
+
9
+ def order_food(food)
10
+ puts "I'll put that order in for you right now"
11
+ sleep(2)
12
+ kitchen.make_food(food)
13
+ serve_food(food)
14
+ end
15
+
16
+ def serve_food(food)
17
+ retrieve_food(food)
18
+ sleep(2)
19
+ puts " <Server retrieved #{food}>"
20
+ return_to_customer(food)
21
+ end
22
+
23
+ def retrieve_food(food)
24
+ kitchen.provide_food(food)
25
+ end
26
+
27
+ def return_to_customer(food)
28
+ puts "Here's your order of #{food}"
29
+ end
30
+
31
+ def pay_bill
32
+ @accountant.accept_funds
33
+ end
34
+ end
@@ -9,11 +9,11 @@ end
9
9
 
10
10
  class Friend
11
11
  def make_me_a_sandwich
12
- Menu.record "I made a sandwich!"
12
+ Table.place "a sandwich!"
13
13
  end
14
14
 
15
15
  def cook(what)
16
- Menu.record what
16
+ Table.place what
17
17
  end
18
18
 
19
19
  def activities
@@ -33,15 +33,15 @@ class Friend
33
33
  end
34
34
  end
35
35
 
36
- module Menu
37
- def self.record(text)
38
- list << text
36
+ module Table
37
+ def self.place(text)
38
+ contents << text
39
39
  end
40
- def self.list
41
- @list ||= []
40
+ def self.contents
41
+ @contents ||= []
42
42
  end
43
43
  def self.clear
44
- @list = []
44
+ @contents = []
45
45
  end
46
46
  end
47
47
 
@@ -64,13 +64,13 @@ describe Direction, 'command' do
64
64
  person
65
65
  }
66
66
  before do
67
- Menu.clear
67
+ Table.clear
68
68
  Activities.clear
69
69
  end
70
70
  it 'forwards a message to another object' do
71
- assert_equal [], Menu.list
71
+ assert_equal [], Table.contents
72
72
  person.make_me_a_sandwich
73
- assert_includes Menu.list, "I made a sandwich!"
73
+ assert_includes Table.contents, "a sandwich!"
74
74
  end
75
75
 
76
76
  it 'returns the original receiver' do
@@ -78,9 +78,9 @@ describe Direction, 'command' do
78
78
  end
79
79
 
80
80
  it 'forwards additional arguments' do
81
- assert_equal [], Menu.list
81
+ assert_equal [], Table.contents
82
82
  person.cook('yum')
83
- assert_includes Menu.list, "yum"
83
+ assert_includes Table.contents, "yum"
84
84
  end
85
85
 
86
86
  it 'forwards block arguments' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: direction
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
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-10-03 00:00:00.000000000 Z
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Forward messages to collaborators in East-oriented style.
14
14
  email:
@@ -26,10 +26,15 @@ files:
26
26
  - direction.gemspec
27
27
  - lib/direction.rb
28
28
  - lib/direction/version.rb
29
+ - sample.rb
30
+ - sample/accountant.rb
31
+ - sample/customer.rb
32
+ - sample/kitchen.rb
33
+ - sample/micro_manager.rb
34
+ - sample/server.rb
29
35
  - test/direction_test.rb
30
- - test/sample.rb
31
36
  - test/test_helper.rb
32
- homepage: ''
37
+ homepage: https://github.com/saturnflyer/direction
33
38
  licenses:
34
39
  - MIT
35
40
  metadata: {}
@@ -55,5 +60,4 @@ specification_version: 4
55
60
  summary: Forward messages to collaborators in East-oriented style.
56
61
  test_files:
57
62
  - test/direction_test.rb
58
- - test/sample.rb
59
63
  - test/test_helper.rb
@@ -1,86 +0,0 @@
1
- require 'direction'
2
-
3
- class MicroManager
4
- def initialize(server)
5
- @server = server
6
- end
7
- attr_accessor :server
8
- end
9
-
10
- class Server
11
- def initialize(kitchen)
12
- @kitchen = kitchen
13
- @accountant = kitchen.accountant
14
- end
15
- attr_reader :kitchen
16
- attr_accessor :customer
17
-
18
- def order_food(food)
19
- puts "I'll put that order in for you right now"
20
- sleep(2)
21
- kitchen.make_food(food)
22
- serve_food(food)
23
- end
24
-
25
- def serve_food(food)
26
- retrieve_food(food)
27
- sleep(2)
28
- puts " <Server retrieved #{food}>"
29
- return_to_customer(food)
30
- end
31
-
32
- def retrieve_food(food)
33
- kitchen.provide_food(food)
34
- end
35
-
36
- def return_to_customer(food)
37
- puts "Here's your order of #{food}"
38
- end
39
-
40
- def pay_bill
41
- @accountant.accept_funds
42
- end
43
- end
44
-
45
- class Kitchen
46
- def make_food(food)
47
- puts " <Kitchen preparing #{food}>"
48
- sleep(3)
49
- puts " <Kitchen made #{food}>"
50
- end
51
-
52
- def provide_food(food)
53
- puts " <Kitchen served up #{food}>"
54
- end
55
-
56
- def accountant
57
- @accountant ||= Accountant.new
58
- end
59
- end
60
-
61
- class Accountant
62
- def accept_funds
63
- puts " $$$ Cha-ching!"
64
- end
65
- end
66
-
67
- class Customer
68
- extend Direction
69
- def initialize(server)
70
- @server = server
71
- end
72
- attr_accessor :server
73
-
74
- command [:order_food, :pay_bill] => :server
75
- end
76
-
77
- def setup
78
- @kitchen = Kitchen.new
79
- @server = Server.new(@kitchen)
80
- @manager = MicroManager.new(@server)
81
- @customer = Customer.new(@server)
82
- @manager
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