casting 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/casting/enum.rb +11 -0
- data/lib/casting/version.rb +1 -1
- data/test/casting_enum_test.rb +40 -0
- data/test/frozen_client_test.rb +14 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87f6f44b2f7597c28ab23eb2d02fd06479558ac075f3b6646cd583ea98e5f945
|
4
|
+
data.tar.gz: cdf55addbcdbaf848d4991fe8562b5bbeb50ea9b3fde1548f210ebb76d761186
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71d6eac4b57b571f8c593606f645477402dd9557081ac684c9c5117257e111916b17ec830836cfe9063acae7572aef5b96e20d5219558bf466769119a95b42a1
|
7
|
+
data.tar.gz: b81bf24dc30d94cbb520eb302f5173efe2f64b19b062a128071c30833df2f92c4a643b47717fa3092afdc2f20cc15a78631b2fa0fab1a80a8e6e9ed18c7bddc9
|
data/lib/casting/enum.rb
ADDED
data/lib/casting/version.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class Person
|
4
|
+
include Casting::Client
|
5
|
+
delegate_missing_methods
|
6
|
+
|
7
|
+
def initialize(name)
|
8
|
+
@name = name
|
9
|
+
end
|
10
|
+
attr_reader :name
|
11
|
+
end
|
12
|
+
|
13
|
+
class PersonCollection
|
14
|
+
include Casting::Enum
|
15
|
+
|
16
|
+
def initialize(array)
|
17
|
+
@array = array
|
18
|
+
end
|
19
|
+
attr_reader :array
|
20
|
+
|
21
|
+
def each(*behaviors, &block)
|
22
|
+
enum(array, *behaviors).each(&block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Hello
|
27
|
+
def hello
|
28
|
+
"Hello, I'm #{name}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Casting::Enum, '#enum' do
|
33
|
+
let(:people){
|
34
|
+
[Person.new('Jim'), Person.new('TJ'), Person.new('Sandi')]
|
35
|
+
}
|
36
|
+
it "iterates and applies behaviors to each item" do
|
37
|
+
client = PersonCollection.new(people)
|
38
|
+
assert_equal ["Hello, I'm Jim", "Hello, I'm TJ", "Hello, I'm Sandi"], client.each(Hello).map(&:hello)
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
describe Casting::Client do
|
4
|
+
it 'will not attempt to alter a frozen client' do
|
5
|
+
client = TestPerson.new
|
6
|
+
client.extend(Casting::Client)
|
7
|
+
client.delegate_missing_methods
|
8
|
+
|
9
|
+
client.freeze
|
10
|
+
|
11
|
+
err = expect{ client.greet }.must_raise(NoMethodError)
|
12
|
+
expect(err.message).must_match(/undefined method \`greet'/)
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: casting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Gay
|
@@ -27,17 +27,20 @@ files:
|
|
27
27
|
- lib/casting/client.rb
|
28
28
|
- lib/casting/context.rb
|
29
29
|
- lib/casting/delegation.rb
|
30
|
+
- lib/casting/enum.rb
|
30
31
|
- lib/casting/method_consolidator.rb
|
31
32
|
- lib/casting/missing_method_client.rb
|
32
33
|
- lib/casting/missing_method_client_class.rb
|
33
34
|
- lib/casting/null.rb
|
34
35
|
- lib/casting/super_delegate.rb
|
35
36
|
- lib/casting/version.rb
|
37
|
+
- test/casting_enum_test.rb
|
36
38
|
- test/casting_test.rb
|
37
39
|
- test/class_refinement_test.rb
|
38
40
|
- test/client_test.rb
|
39
41
|
- test/context_test.rb
|
40
42
|
- test/delegation_test.rb
|
43
|
+
- test/frozen_client_test.rb
|
41
44
|
- test/method_consolidator_test.rb
|
42
45
|
- test/missing_method_client_test.rb
|
43
46
|
- test/module_cleanup_test.rb
|
@@ -63,19 +66,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
66
|
- !ruby/object:Gem::Version
|
64
67
|
version: '0'
|
65
68
|
requirements: []
|
66
|
-
rubygems_version: 3.
|
69
|
+
rubygems_version: 3.2.27
|
67
70
|
signing_key:
|
68
71
|
specification_version: 4
|
69
72
|
summary: Proper method delegation.
|
70
73
|
test_files:
|
71
74
|
- test/test_helper.rb
|
75
|
+
- test/casting_enum_test.rb
|
72
76
|
- test/casting_test.rb
|
73
77
|
- test/class_refinement_test.rb
|
74
78
|
- test/client_test.rb
|
75
79
|
- test/context_test.rb
|
76
80
|
- test/delegation_test.rb
|
81
|
+
- test/frozen_client_test.rb
|
77
82
|
- test/method_consolidator_test.rb
|
78
83
|
- test/missing_method_client_test.rb
|
79
|
-
- test/null_module_test.rb
|
80
84
|
- test/module_cleanup_test.rb
|
85
|
+
- test/null_module_test.rb
|
81
86
|
- test/super_test.rb
|