hook_lying_syncer 0.0.1 → 0.0.3
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 +4 -4
- data/.travis.yml +15 -0
- data/README.md +22 -3
- data/Rakefile +3 -1
- data/hook_lying_syncer.gemspec +9 -6
- data/lib/hook_lying_syncer/version.rb +1 -1
- data/spec/hook_lying_syncer_spec.rb +59 -43
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be6aa31c687c6e6c52debf2208e624d7af9b01f4
|
4
|
+
data.tar.gz: 9db2017a92e4f12fe3d5aecdcfac7ac5c9db6cab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4779f862d8b3b23aa591e1a4c8b2b4785c043ee38929e67c2744f4e55a4c7cd63b59d16a0a8ca73bc6581f3c3f524cf45c16bfaef0e34dfec634df0c7f5f5edf
|
7
|
+
data.tar.gz: 7c95f578b5422bf10c62e2eafb9b305447e9e2aa647b16e01826ded859d20fe418473d6acb87e867e2428e865457f9ea85cbe7bbc97b0edda5110ada4beb706a
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
hook_lying_syncer
|
2
2
|
=================
|
3
3
|
|
4
|
+
[](https://codeclimate.com/github/davearonson/hook_lying_syncer)
|
5
|
+
[](https://travis-ci.org/davearonson/hook_lying_syncer)
|
6
|
+
|
4
7
|
This project presents a way for Ruby coders to keep method_missing and
|
5
8
|
respond_to_missing? in sync.
|
6
9
|
|
@@ -23,6 +26,17 @@ I got some suggestions and other help from [Chris
|
|
23
26
|
Hoffman](https://github.com/yarmiganosca), mainly in figuring out that I
|
24
27
|
shouldn't do the in-block object access the way I was trying to! :-)
|
25
28
|
|
29
|
+
|
30
|
+
## Caveats
|
31
|
+
|
32
|
+
This requires the Ruby version to be at least 1.9. Eventually I might put some
|
33
|
+
work into figuring out why many tests fail with 1.8, but for now, call it a
|
34
|
+
Ruby 1.9+ gem. Check [its Travis CI status
|
35
|
+
page](https://travis-ci.org/davearonson/hook_lying_syncer) to see which
|
36
|
+
versions of Ruby it has been tested against; currently that's 1.9.2, 1.9.3,
|
37
|
+
2.0.0, 2.1.0, 2.1.1, 2.1.2, JRuby in 1.9 mode, and Rubinius 2.1.1.
|
38
|
+
|
39
|
+
|
26
40
|
## Installation
|
27
41
|
|
28
42
|
Add this line to your application's Gemfile:
|
@@ -66,10 +80,15 @@ a match.
|
|
66
80
|
|
67
81
|
See the tests for examples.
|
68
82
|
|
69
|
-
## Status
|
70
83
|
|
71
|
-
|
72
|
-
|
84
|
+
## Changes
|
85
|
+
|
86
|
+
| Version | Change |
|
87
|
+
|---|---|
|
88
|
+
| 0.0.1 | Initial release |
|
89
|
+
| 0.0.2 | Better compatibility w/ 1.9; declare 1.8 incompatible in README |
|
90
|
+
| 0.0.3 | Declare 1.8 incompatible in gemspec (duh!) |
|
91
|
+
|
73
92
|
|
74
93
|
## Contributing
|
75
94
|
|
data/Rakefile
CHANGED
data/hook_lying_syncer.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
lib = File.expand_path(
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
4
|
+
require "hook_lying_syncer/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "hook_lying_syncer"
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Dave Aronson"]
|
10
10
|
spec.email = ["hook_lying_syncer_gemspec.2.TRex@Codosaur.us"]
|
11
11
|
spec.summary = %q{Keeps method_missing and respond_to_missing? in sync.}
|
12
|
-
spec.description = %q{Provides a decorator class you can wrap objects in (even classes!) to keep method_missing and respond_to_missing? in sync.}
|
12
|
+
spec.description = %q{Provides a decorator class you can wrap objects in (even classes!) to keep method_missing and respond_to_missing? in sync. Requires Ruby 1.9 or later; see README for details.}
|
13
13
|
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -17,8 +17,11 @@ 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
|
+
spec.required_ruby_version = '>= 1.9'
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
spec.add_development_dependency "
|
22
|
+
# no version numbers 'cuz they're only dev dependencies and having too-high
|
23
|
+
# numbers could make dependency resolution impossible for older rubies
|
24
|
+
spec.add_development_dependency "bundler", "~> 0"
|
25
|
+
spec.add_development_dependency "rake", "~> 0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 0"
|
24
27
|
end
|
@@ -1,40 +1,5 @@
|
|
1
1
|
require 'hook_lying_syncer'
|
2
2
|
|
3
|
-
def lambda_maker(prefix, separator, suffix=nil)
|
4
|
-
lambda { |method_name|
|
5
|
-
matches = /\A#{prefix}(\w+)#{suffix}\Z/.match(method_name)
|
6
|
-
matches[1].split(separator) if matches
|
7
|
-
}
|
8
|
-
end
|
9
|
-
|
10
|
-
class Person
|
11
|
-
attr_reader :name
|
12
|
-
def initialize(name)
|
13
|
-
@name = name
|
14
|
-
end
|
15
|
-
def self.find(params)
|
16
|
-
self.seek("Looking for", params)
|
17
|
-
end
|
18
|
-
def self.need(params)
|
19
|
-
self.seek("I need", params)
|
20
|
-
end
|
21
|
-
def self.what_are_they
|
22
|
-
"Are we not men? We are Devo! D-E-V-O!"
|
23
|
-
end
|
24
|
-
private
|
25
|
-
def self.seek(look_how, params)
|
26
|
-
wants = [].tap { |list| params.each { |key, val| list << "#{val} #{key}" } }
|
27
|
-
|
28
|
-
# there's got to be some way to do this more cleanly...
|
29
|
-
# wouldn't be surprised if Rails has something like Array#sentencize....
|
30
|
-
wants[-1] = "and #{wants[-1]}" if wants.length > 1
|
31
|
-
separator = wants.length > 2 ? ", " : " "
|
32
|
-
description = wants.join(separator)
|
33
|
-
|
34
|
-
"#{look_how} a person with #{ description }"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
3
|
describe HookLyingSyncer do
|
39
4
|
|
40
5
|
describe "on instances" do
|
@@ -110,9 +75,7 @@ describe HookLyingSyncer do
|
|
110
75
|
it "can add methods" do
|
111
76
|
method_matcher = lambda { |name| name == :foo ? [name] : nil }
|
112
77
|
syncer = HookLyingSyncer.new(@person, method_matcher) do |p, wants, *args|
|
113
|
-
|
114
|
-
:foo
|
115
|
-
end
|
78
|
+
:foo
|
116
79
|
end
|
117
80
|
expect(syncer.foo).to equal :foo
|
118
81
|
end
|
@@ -189,7 +152,8 @@ describe HookLyingSyncer do
|
|
189
152
|
if wants.length != args.length
|
190
153
|
raise "#{wants.length} qualities but #{args.length} values"
|
191
154
|
end
|
192
|
-
|
155
|
+
# can't use to_h prior to ruby 2.0
|
156
|
+
c.find to_hash_kluge(wants.zip(args))
|
193
157
|
end
|
194
158
|
end
|
195
159
|
|
@@ -210,9 +174,7 @@ describe HookLyingSyncer do
|
|
210
174
|
it "to add class methods" do
|
211
175
|
method_matcher = lambda { |name| name == :foo ? [name] : nil }
|
212
176
|
syncer = HookLyingSyncer.new(Person, method_matcher) do |c, wants, *args|
|
213
|
-
|
214
|
-
:foo
|
215
|
-
end
|
177
|
+
:foo
|
216
178
|
end
|
217
179
|
expect(syncer.foo).to equal :foo
|
218
180
|
end
|
@@ -246,7 +208,8 @@ describe HookLyingSyncer do
|
|
246
208
|
before do
|
247
209
|
needs_getter = lambda_maker("need_with_", "_and_")
|
248
210
|
@outer = HookLyingSyncer.new(@syncer, needs_getter) do |c, wants, *args|
|
249
|
-
|
211
|
+
# can't use to_h prior to ruby 2.0
|
212
|
+
c.need to_hash_kluge(wants.zip(args))
|
250
213
|
end
|
251
214
|
end
|
252
215
|
|
@@ -269,3 +232,56 @@ describe HookLyingSyncer do
|
|
269
232
|
end
|
270
233
|
|
271
234
|
end
|
235
|
+
|
236
|
+
private
|
237
|
+
|
238
|
+
def lambda_maker(prefix, separator, suffix=nil)
|
239
|
+
lambda { |method_name|
|
240
|
+
matches = /\A#{prefix}(\w+)#{suffix}\Z/.match(method_name.to_s)
|
241
|
+
matches[1].split(separator) if matches
|
242
|
+
}
|
243
|
+
end
|
244
|
+
|
245
|
+
class Person
|
246
|
+
|
247
|
+
attr_reader :name
|
248
|
+
|
249
|
+
def initialize(name)
|
250
|
+
@name = name
|
251
|
+
end
|
252
|
+
|
253
|
+
def self.find(params)
|
254
|
+
self.seek("Looking for", params)
|
255
|
+
end
|
256
|
+
|
257
|
+
def self.need(params)
|
258
|
+
self.seek("I need", params)
|
259
|
+
end
|
260
|
+
|
261
|
+
def self.what_are_they
|
262
|
+
"Are we not men? We are Devo! D-E-V-O!"
|
263
|
+
end
|
264
|
+
|
265
|
+
private
|
266
|
+
|
267
|
+
def self.seek(look_how, params)
|
268
|
+
wants = [].tap { |list| params.each { |key, val| list << "#{val} #{key}" } }
|
269
|
+
|
270
|
+
# there's got to be some way to do this more cleanly...
|
271
|
+
# wouldn't be surprised if Rails has something like Array#sentencize....
|
272
|
+
wants[-1] = "and #{wants[-1]}" if wants.length > 1
|
273
|
+
separator = wants.length > 2 ? ", " : " "
|
274
|
+
description = wants.join(separator)
|
275
|
+
|
276
|
+
"#{look_how} a person with #{ description }"
|
277
|
+
end
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
# since we can't use .to_h prior to ruby 2.0,
|
282
|
+
# and we want this gem to be usable w/ 1.8 and 1.9
|
283
|
+
def to_hash_kluge(ary)
|
284
|
+
hash = {}
|
285
|
+
ary.each { |pair| hash[pair.first] = pair.last }
|
286
|
+
hash
|
287
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hook_lying_syncer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Aronson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,44 +16,45 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: Provides a decorator class you can wrap objects in (even classes!) to
|
56
|
-
keep method_missing and respond_to_missing? in sync.
|
56
|
+
keep method_missing and respond_to_missing? in sync. Requires Ruby 1.9 or later;
|
57
|
+
see README for details.
|
57
58
|
email:
|
58
59
|
- hook_lying_syncer_gemspec.2.TRex@Codosaur.us
|
59
60
|
executables: []
|
@@ -61,6 +62,7 @@ extensions: []
|
|
61
62
|
extra_rdoc_files: []
|
62
63
|
files:
|
63
64
|
- ".gitignore"
|
65
|
+
- ".travis.yml"
|
64
66
|
- Gemfile
|
65
67
|
- LICENSE.txt
|
66
68
|
- README.md
|
@@ -81,7 +83,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
83
|
requirements:
|
82
84
|
- - ">="
|
83
85
|
- !ruby/object:Gem::Version
|
84
|
-
version: '
|
86
|
+
version: '1.9'
|
85
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
88
|
requirements:
|
87
89
|
- - ">="
|