direction 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
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +12 -0
- data/direction.gemspec +23 -0
- data/lib/direction/version.rb +3 -0
- data/lib/direction.rb +31 -0
- data/test/direction_test.rb +45 -0
- data/test/test_helper.rb +3 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cf0d1561e0306c26af0ec8f3edf6e47c76b16efe
|
4
|
+
data.tar.gz: a02622d5f95b89ac8d00a32bd7e461ac9350f690
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d0fe301a31181cf872d9551225e355b20fb1fa205c95f23379fb1b2364910677b0e52d315cb828baffc1ea228ff23e1878a63bcd0e9b52615e2b379dc4c8bea4
|
7
|
+
data.tar.gz: e32e256f3cdba9bb51b2cf49736cc44ba66b816f9337e090c97da7fef2d151438a409ef2309c93fb81de06d8578e9e4ffcdbdaf4e53f30e5f88ed2918cb37350
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 'Jim Gay'
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Direction
|
2
|
+
|
3
|
+
Enforce better encapsulation by returning self from commands.
|
4
|
+
|
5
|
+
Thanks to James Ladd for the inspiration.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
Provide a feature like the Forwardable library, but set the return value to self.
|
10
|
+
|
11
|
+
It provides a class level "command" method to do message forwarding.
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
class SomeClass
|
15
|
+
extend Direction
|
16
|
+
|
17
|
+
command [:name, :id] => :collaborator, [:color, :type] => :partner
|
18
|
+
end
|
19
|
+
```
|
20
|
+
|
21
|
+
This will define methods on instances that forward to the provided receiver while enforcing encapsulation of the relationship between objects.
|
22
|
+
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
gem 'direction'
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
$ gem install direction
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( http://github.com/saturnflyer/direction/fork )
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/direction.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'direction/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "direction"
|
8
|
+
spec.version = Direction::VERSION
|
9
|
+
spec.authors = ["'Jim Gay'"]
|
10
|
+
spec.email = ["jim@saturnflyer.com"]
|
11
|
+
spec.summary = %q{Forward messages to collaborators in East-oriented style.}
|
12
|
+
spec.description = %q{Forward messages to collaborators in East-oriented style.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
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)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/direction.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "direction/version"
|
2
|
+
# Provide a feature like the Forwardable library,
|
3
|
+
# but set the return value to self.
|
4
|
+
# It provides a class level "command" method to do
|
5
|
+
# message forwarding.
|
6
|
+
#
|
7
|
+
# class SomeClass
|
8
|
+
# extend Direction
|
9
|
+
#
|
10
|
+
# command [:name, :id] => :collaborator, [:color, :type] => :@partner
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# This will define methods on instances that forward to the
|
14
|
+
# provided receiver while enforcing encapsulation of the
|
15
|
+
# relationship between objects.
|
16
|
+
module Direction
|
17
|
+
def command(options)
|
18
|
+
method_defs = []
|
19
|
+
options.each_pair do |key, value|
|
20
|
+
Array(key).map do |command_name|
|
21
|
+
method_defs.unshift %{
|
22
|
+
def #{command_name}(*args, &block)
|
23
|
+
#{value}.__send__(:#{command_name})
|
24
|
+
self
|
25
|
+
end
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
self.class_eval method_defs.join(' ')
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Person
|
4
|
+
extend Direction
|
5
|
+
command :make_me_a_sandwich => :@friend
|
6
|
+
attr_accessor :friend
|
7
|
+
end
|
8
|
+
|
9
|
+
class Friend
|
10
|
+
def make_me_a_sandwich
|
11
|
+
Menu.record "I made a sandwich!"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Menu
|
16
|
+
def self.record(text)
|
17
|
+
list << text
|
18
|
+
end
|
19
|
+
def self.list
|
20
|
+
@list ||= []
|
21
|
+
end
|
22
|
+
def self.clear
|
23
|
+
@list = []
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe Direction do
|
28
|
+
let(:friend){ Friend.new }
|
29
|
+
let(:person){ person = Person.new
|
30
|
+
person.friend = friend
|
31
|
+
person
|
32
|
+
}
|
33
|
+
before do
|
34
|
+
Menu.clear
|
35
|
+
end
|
36
|
+
it 'forwards a message to another object' do
|
37
|
+
assert_equal [], Menu.list
|
38
|
+
person.make_me_a_sandwich
|
39
|
+
assert_includes Menu.list, "I made a sandwich!"
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'returns the original receiver' do
|
43
|
+
assert_equal person, person.make_me_a_sandwich
|
44
|
+
end
|
45
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: direction
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- "'Jim Gay'"
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-07 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'
|
41
|
+
description: Forward messages to collaborators in East-oriented style.
|
42
|
+
email:
|
43
|
+
- jim@saturnflyer.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- direction.gemspec
|
54
|
+
- lib/direction.rb
|
55
|
+
- lib/direction/version.rb
|
56
|
+
- test/direction_test.rb
|
57
|
+
- test/test_helper.rb
|
58
|
+
homepage: ''
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.2.0
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Forward messages to collaborators in East-oriented style.
|
82
|
+
test_files:
|
83
|
+
- test/direction_test.rb
|
84
|
+
- test/test_helper.rb
|