y_support 2.1.17 → 2.1.18

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9e7c3554d0b668a729d67e66d02ff58306080757
4
- data.tar.gz: 925b0d2ad87a9d5bf06af86a99f5dcfa152a61c2
3
+ metadata.gz: 120a7bb4137ae4605604f405ed60fe3cc3f927b4
4
+ data.tar.gz: e2ba99d2c42fc89f0750262f42d6d8b7572a6c47
5
5
  SHA512:
6
- metadata.gz: 30a986280eca560719e42884223f74cb4bca22f56cdfe04a45a8063d4fb9530d713e3d7c87f1babc1fdda834110397d42f6a94c83ed3ba90fa45b4aa9c026ddd
7
- data.tar.gz: cad946575666768b918b6b847e2fe7c5e00f9b7c8e2a9e40981eb42757df5e2a8ce1e2309949c25fd7cd706dd48bc937261de1dbd9f75c11935b082ec83193d9
6
+ metadata.gz: 8eabfab794856a0b786ba8861d97a1909618279a55861ea96f6bd40d18f6267d511945429fa63a52d078f5675e78f3ea00032ec1e22d439935a2322a84a38f60
7
+ data.tar.gz: 9434baf3adbd88fc9c0161bc193cbc14db37cebc2518c2a934149a4e9a7bb1c455c050f79024952e795092e6f7efe9736db39d83c82f86cd4138e8efa427d780
@@ -1,3 +1,5 @@
1
+ require File.dirname( __FILE__ ) + '/../module'
2
+
1
3
  class Class
2
4
  # Creates a subclass of the current class parametrized with a given set of
3
5
  # parameters. The parameters have form { symbol: value } and they cause
@@ -1,5 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
+ require File.dirname( __FILE__ ) + '/../module'
3
4
  require File.dirname( __FILE__ ) + '/../class'
4
5
 
5
6
  class Object
@@ -29,27 +30,35 @@ class Object
29
30
  # returned.
30
31
  #
31
32
  def set_attr_with_readers! hash
32
- hash.each_pair { |symbol, value|
33
- instance_variable_set "@#{symbol}", value
33
+ hash.each_pair { |ß, value|
34
+ instance_variable_set "@#{ß}", value
34
35
  singleton_class.class_exec do
35
- define_method symbol do |*args, &block|
36
- return instance_variable_get "@#{symbol}" if args.empty? && block.nil?
36
+ define_method ß do |*args, &block|
37
+ return instance_variable_get "@#{ß}" if args.empty? && block.nil?
37
38
  super *args, &block
38
39
  end
39
40
  end
40
41
  }
41
42
  end
42
43
 
43
- # Constructs parametrized subclasses of the supplied classes and makes them
44
- # available under specified getters. Expects a hash of pairs { symbol: class },
45
- # and a hash of parameters with which to parametrize the class(es). Guards
46
- # against collisions in the subclass getter symbols, rasing NameError should
47
- # these shadow or overwrite existing methods.
44
+ # Constructs heir classes (parametrized subclasses) of the supplied modules
45
+ # (classes) and makes them available under specified getters. Expects a hash of
46
+ # pairs { symbol: class }, and a hash of parameters with which to parametrize
47
+ # the modules (classes). The methods guards against collisions in the subclass
48
+ # getter symbols, rasing +NameError+ should these shadow or overwrite existing
49
+ # methods.
48
50
  #
49
51
  def param_class( hash, with: {} )
50
- hash.each { |ß, ç|
51
- sub = ç.parametrize( with )
52
- set_attr_with_readers( ß => sub )
52
+ hash.each { |ß, m|
53
+ case m
54
+ when Class then
55
+ parametrized_subclass = m.parametrize( with )
56
+ set_attr_with_readers( ß => parametrized_subclass )
57
+ when Module then
58
+ heir_class = m.heir_class( with )
59
+ set_attr_with_readers( ß => heir_class )
60
+ else fail TypeError, "#{m} must be a module or a class!"
61
+ end
53
62
  }
54
63
  return nil
55
64
  end
@@ -59,9 +68,16 @@ class Object
59
68
  # for full explanation of the shadowing / overwriting behavior.
60
69
  #
61
70
  def param_class!( hash, with: {} )
62
- hash.each { |ß, ç|
63
- sub = ç.parametrize( with )
64
- set_attr_with_readers!( ß => sub )
71
+ hash.each { |ß, m|
72
+ case m
73
+ when Class then
74
+ parametrized_subclass = m.parametrize( with )
75
+ set_attr_with_readers!( ß => parametrized_subclass )
76
+ when Module then
77
+ heir_class = m.heir_class( with )
78
+ set_attr_with_readers!( ß => heir_class )
79
+ else fail TypeError, "#{m} must be a module or a class!"
80
+ end
65
81
  }
66
82
  return nil
67
83
  end
@@ -1,4 +1,4 @@
1
1
  module YSupport
2
- VERSION = "2.1.17"
2
+ VERSION = "2.1.18"
3
3
  DEBUG = false
4
4
  end
data/test/misc_test.rb CHANGED
@@ -10,10 +10,24 @@ describe Object do
10
10
 
11
11
  it "should have #param_class" do
12
12
  o = Object.new
13
- o.param_class( { Array: Array, foo: Hash }, with: { mother: o } )
13
+ m = Module.new
14
+ o.param_class( { Array: Array, foo: Hash, bar: m }, with: { mother: o } )
15
+ assert o.Array < Array
16
+ o.Array.mother.must_equal( o )
17
+ o.foo.mother.must_equal( o )
18
+ o.bar.ancestors[1].must_equal( m )
19
+ o.bar.mother.must_equal( o )
20
+ end
21
+
22
+ it "should have #param_class!" do
23
+ o = Object.new
24
+ m = Module.new
25
+ o.param_class!( { Array: Array, foo: Hash, bar: m }, with: { mother: o } )
14
26
  assert o.Array < Array
15
27
  o.Array.mother.must_equal( o )
16
28
  o.foo.mother.must_equal( o )
29
+ o.bar.ancestors[1].must_equal( m )
30
+ o.bar.mother.must_equal( o )
17
31
  end
18
32
  end
19
33
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: y_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.17
4
+ version: 2.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - boris