festoon 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 +14 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/festoon.gemspec +25 -0
- data/lib/festoon.rb +5 -0
- data/lib/festoon/dynamic.rb +41 -0
- data/lib/festoon/version.rb +3 -0
- data/spec/festoon/dynamic_spec.rb +82 -0
- data/spec/spec_helper.rb +28 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0b7a0e99c5266b86d2ef45319bbd2a93718ebb5a
|
4
|
+
data.tar.gz: 2434b18a8451083589f120a91dbfb9c694c9ab1b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2d860a3ace6f18ccc60588a332cecdd137abfb1ac56ef30f80d20eaeedfc233e091403ec0f7103722d11f1bb2c6cfe188f13d8bd106e92677531edb9ee79d350
|
7
|
+
data.tar.gz: 60c719f3ffd1d34c2eee31b845ea8ccdc660184e57114a12a4dc696cbc00bba69e166475434c69f5e43e31d3610d0171cfa0cb1c1d4b10d8c2007d2dd7296175
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Stephen Best
|
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,31 @@
|
|
1
|
+
# Festoon
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'festoon'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install festoon
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/festoon/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/festoon.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'festoon/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "festoon"
|
8
|
+
spec.version = Festoon::VERSION
|
9
|
+
spec.authors = ["Stephen Best"]
|
10
|
+
spec.email = ["bestie@gmail.com"]
|
11
|
+
spec.summary = %q{Tools for better object composition and decoration}
|
12
|
+
spec.homepage = "https://github.com/bestie/festoon"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
23
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
24
|
+
spec.add_development_dependency "awesome_print", "~> 1.2"
|
25
|
+
end
|
data/lib/festoon.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Festoon
|
2
|
+
class Dynamic
|
3
|
+
def initialize(thing)
|
4
|
+
@thing = thing
|
5
|
+
end
|
6
|
+
|
7
|
+
def method_missing(method_id, *args, &block)
|
8
|
+
intercept_return_self(thing.public_send(method_id, *args, &block))
|
9
|
+
end
|
10
|
+
|
11
|
+
def __decompose__
|
12
|
+
if thing.respond_to?(:__decompose__)
|
13
|
+
[self, *thing.__decompose__]
|
14
|
+
else
|
15
|
+
[self, thing]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def ==(other)
|
20
|
+
if other.is_a?(self.class)
|
21
|
+
other == thing
|
22
|
+
else
|
23
|
+
thing == other
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def thing
|
30
|
+
@thing
|
31
|
+
end
|
32
|
+
|
33
|
+
def intercept_return_self(value)
|
34
|
+
value == thing ? self : value
|
35
|
+
end
|
36
|
+
|
37
|
+
def respond_to_missing?(method_id, *args)
|
38
|
+
thing.respond_to?(method_id)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
require "festoon/dynamic"
|
4
|
+
|
5
|
+
RSpec.describe Festoon::Dynamic do
|
6
|
+
subject(:composed_object) { Festoon::Dynamic.new(underlying_object) }
|
7
|
+
let(:underlying_object) { double(:underlying_object) }
|
8
|
+
|
9
|
+
context "when a method is not implemented by the decorator" do
|
10
|
+
let(:arguments) { [double, double] }
|
11
|
+
|
12
|
+
it "delegates messages" do
|
13
|
+
expect(underlying_object).to receive(:arbitrary_message)
|
14
|
+
.with(*arguments)
|
15
|
+
|
16
|
+
composed_object.arbitrary_message(*arguments)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "delegates with the block" do
|
20
|
+
allow(underlying_object).to receive(:arbitrary_message).and_yield
|
21
|
+
|
22
|
+
expect { |blk|
|
23
|
+
composed_object.arbitrary_message(&blk)
|
24
|
+
}.to yield_with_no_args
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "methods on the underlying object that return self" do
|
29
|
+
before do
|
30
|
+
allow(underlying_object).to receive(:arbitrary_message)
|
31
|
+
.and_return(underlying_object)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns self to maintain decoration" do
|
35
|
+
expect(composed_object.arbitrary_message).to be(composed_object)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#respond_to?" do
|
40
|
+
before do
|
41
|
+
allow(underlying_object).to receive(:arbitrary_message)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "responds to its own methods" do
|
45
|
+
expect(composed_object).to respond_to(:__decompose__)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "purports to respond to messages that the underlying object responds to" do
|
49
|
+
expect(composed_object).to respond_to(:arbitrary_message)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#==" do
|
54
|
+
let(:object) { Object.new }
|
55
|
+
let(:other) { Object.new }
|
56
|
+
|
57
|
+
let(:composed_object) { Festoon::Dynamic.new(object) }
|
58
|
+
|
59
|
+
it "delegates equality to the underlying object" do
|
60
|
+
expect(composed_object == object).to be(true)
|
61
|
+
expect(composed_object == other).to be(false)
|
62
|
+
end
|
63
|
+
|
64
|
+
context "when comparing to another decorator" do
|
65
|
+
let(:composed_similar) { Festoon::Dynamic.new(object) }
|
66
|
+
|
67
|
+
it "inverts the operation offering up its underying object for comparison" do
|
68
|
+
expect(composed_object == composed_similar).to be(true)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#__decompose__" do
|
74
|
+
let(:base_object) { Object.new }
|
75
|
+
let(:middle_wrap) { Festoon::Dynamic.new(base_object) }
|
76
|
+
let(:top_wrap) { Festoon::Dynamic.new(middle_wrap) }
|
77
|
+
|
78
|
+
it "recursivly unwraps the composed objects into a flat array" do
|
79
|
+
expect(top_wrap.__decompose__).to eq([top_wrap, middle_wrap, base_object])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
2
|
+
require "awesome_print"
|
3
|
+
require "pry"
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.disable_monkey_patching!
|
7
|
+
|
8
|
+
config.filter_run :focus
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
|
11
|
+
if config.files_to_run.one?
|
12
|
+
config.default_formatter = 'doc'
|
13
|
+
end
|
14
|
+
|
15
|
+
config.order = :random
|
16
|
+
|
17
|
+
Kernel.srand config.seed
|
18
|
+
|
19
|
+
config.expect_with :rspec do |expectations|
|
20
|
+
expectations.syntax = :expect
|
21
|
+
end
|
22
|
+
|
23
|
+
config.mock_with :rspec do |mocks|
|
24
|
+
mocks.syntax = :expect
|
25
|
+
|
26
|
+
mocks.verify_partial_doubles = true
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: festoon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stephen Best
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-31 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: awesome_print
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.2'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- bestie@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- festoon.gemspec
|
97
|
+
- lib/festoon.rb
|
98
|
+
- lib/festoon/dynamic.rb
|
99
|
+
- lib/festoon/version.rb
|
100
|
+
- spec/festoon/dynamic_spec.rb
|
101
|
+
- spec/spec_helper.rb
|
102
|
+
homepage: https://github.com/bestie/festoon
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.2.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Tools for better object composition and decoration
|
126
|
+
test_files:
|
127
|
+
- spec/festoon/dynamic_spec.rb
|
128
|
+
- spec/spec_helper.rb
|