casting 1.0.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a7d5101d4c7109e86710609589a9f7dcd4d9d5452e7a452fa29349297325d9a7
4
- data.tar.gz: 5854e95575b52af1b6d912a5aa3dc18101faa109d9bea387dba59b6bd50b9df7
3
+ metadata.gz: 87f6f44b2f7597c28ab23eb2d02fd06479558ac075f3b6646cd583ea98e5f945
4
+ data.tar.gz: cdf55addbcdbaf848d4991fe8562b5bbeb50ea9b3fde1548f210ebb76d761186
5
5
  SHA512:
6
- metadata.gz: 1b394e9b29860bc90654751bc36296ddf5d67598bddf7a3bcec570d507a31ed62674ddce23cfa25a7a6f8d202664c131fec735f3bd4de2074940f88f3860a9f3
7
- data.tar.gz: 3e02eb89ad5894b7866569e21aa2efb00e5d00ce9a1d74d1d0865bf7b67303e9a3ddf82333044411a4f1f4f54ff3e0296b42cddaffba1c978609c8f335db2ce7
6
+ metadata.gz: 71d6eac4b57b571f8c593606f645477402dd9557081ac684c9c5117257e111916b17ec830836cfe9063acae7572aef5b96e20d5219558bf466769119a95b42a1
7
+ data.tar.gz: b81bf24dc30d94cbb520eb302f5173efe2f64b19b062a128071c30833df2f92c4a643b47717fa3092afdc2f20cc15a78631b2fa0fab1a80a8e6e9ed18c7bddc9
@@ -0,0 +1,11 @@
1
+ module Casting
2
+ module Enum
3
+ def enum(collection, *behaviors)
4
+ enum = Enumerator.new do |yielder|
5
+ collection.each do |item|
6
+ yielder.yield(item.cast_as(*behaviors))
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Casting
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -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.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.1.6
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