ruby-features 1.2.0 → 1.2.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
  SHA1:
3
- metadata.gz: 27643cb1fa6b12baf10bf86fbc40226e2e70bc08
4
- data.tar.gz: 2be53a6cc1404b1709b910fb8390663f4fc2d801
3
+ metadata.gz: a3632d4e9a9c9f523e3c5279507d817125afd3b3
4
+ data.tar.gz: 96790e0dd4cc23a527c790490c328643cb0eb1ca
5
5
  SHA512:
6
- metadata.gz: c03d3cef6917da453e06c12184e31988366f42183ed170a6308049ce87dd8790dfafb3a41df9151a49672c7d1a161359634638f3873f11b60d0695cbdc89f6d0
7
- data.tar.gz: 170853e803e73904e1755fc688e24032d45df28304a5f12427f4e9a3f259b3de9a6978afb6f67c36af5ee4da7fb12836a894a786abc078ccba58c22383ba8a44
6
+ metadata.gz: d8826d60283b8688f51d71277fb105f0d3258e4714f64296247ef460e88208a826a4192baab2597c5cf88875930c83ab64e63cd8cd77316af1ac8d16de017433
7
+ data.tar.gz: 20aa851febfc4ce36ffb7b97c1436f9afb9b6a6ba98a13562250895c8a525fa34b3cad6f2f7bf2792e3c296da8d0cc2d9203f10697442ae09426eb511910ee77
@@ -26,38 +26,43 @@ module RubyFeatures
26
26
  end
27
27
 
28
28
  def class_methods(asserts = {}, &block)
29
- _methods('Extend', asserts, block)
29
+ _methods('AddClassMethods', asserts, block)
30
30
  end
31
31
 
32
32
  def instance_methods(asserts = {}, &block)
33
- _methods('Include', asserts, block)
33
+ _methods('AddInstanceMethods', asserts, block)
34
34
  end
35
35
 
36
36
  def rewrite_instance_methods(asserts = {}, &block)
37
- _methods('RewriteInstance', asserts, block)
37
+ _methods('RewriteInstanceMethods', asserts, block)
38
38
  end
39
39
 
40
40
  def _apply_methods(target_class)
41
- constants.each do |constant|
42
- mixin_method, existing_methods_method, existing_methods_check = case(constant)
43
- when /^Extend/ then [:extend, :methods, :exclusion]
44
- when /^Include/ then [:include, :instance_methods, :exclusion]
45
- when /^RewriteInstance/ then [:prepend, :instance_methods, :inclusion]
46
- else raise ArgumentError.new("Wrong mixin constant: #{constant}")
47
- end
41
+ target_class_methods = target_class.methods + target_class.private_methods
42
+ target_instance_methods = target_class.instance_methods + target_class.private_instance_methods
48
43
 
44
+ constants.each do |constant|
49
45
  mixin = const_get(constant)
46
+ mixin_methods = mixin.instance_methods + mixin.private_instance_methods
50
47
 
51
- case(existing_methods_check)
52
- when :exclusion
53
- existing_methods = mixin.instance_methods & target_class.public_send(existing_methods_method)
54
- raise NameError.new("Tried to #{mixin_method} already existing methods: #{existing_methods.inspect}") unless existing_methods.empty?
55
- when :inclusion
56
- not_existing_methods = mixin.instance_methods - target_class.public_send(existing_methods_method)
57
- raise NameError.new("Tried to #{mixin_method} not existing methods: #{not_existing_methods.inspect}") unless not_existing_methods.empty?
58
- end
48
+ case(constant)
49
+ when /^AddClassMethods/
50
+ existing_methods = mixin_methods & target_class_methods
51
+ raise NameError.new("Tried to add already existing class methods: #{existing_methods.inspect}") unless existing_methods.empty?
52
+ target_class.send(:extend, mixin)
59
53
 
60
- target_class.send(mixin_method, mixin)
54
+ when /^AddInstanceMethods/
55
+ existing_methods = mixin_methods & target_instance_methods
56
+ raise NameError.new("Tried to add already existing instance methods: #{existing_methods.inspect}") unless existing_methods.empty?
57
+ target_class.send(:include, mixin)
58
+
59
+ when /^RewriteInstanceMethods/
60
+ not_existing_methods = mixin_methods - target_instance_methods
61
+ raise NameError.new("Tried to rewrite not existing instance methods: #{not_existing_methods.inspect}") unless not_existing_methods.empty?
62
+ target_class.send(:prepend, mixin)
63
+
64
+ else raise ArgumentError.new("Wrong mixin constant: #{constant}")
65
+ end
61
66
  end
62
67
  end
63
68
 
@@ -1,3 +1,3 @@
1
1
  module RubyFeatures
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.2.1'.freeze
3
3
  end
@@ -54,7 +54,7 @@ describe RubyFeatures do
54
54
  expect(subject).to_not respond_to(:boolean_false)
55
55
 
56
56
  expect(subject.singleton_class.included_modules).to include(
57
- RubyFeatures::Mixins::ConditionsTestFeature::ConditionsTestClass::ExtendIfBooleanIsTrueAndStringIsString
57
+ RubyFeatures::Mixins::ConditionsTestFeature::ConditionsTestClass::AddClassMethodsIfBooleanIsTrueAndStringIsString
58
58
  )
59
59
  end
60
60
 
@@ -13,7 +13,7 @@ describe RubyFeatures::Concern::Feature do
13
13
 
14
14
 
15
15
  expect(test_class.singleton_class.included_modules).to include(
16
- RubyFeatures::Mixins::DefineTestModule::DefineTestClass::ClassMethodsFeature::DefineTestModule::DefineTestClass::Extend
16
+ RubyFeatures::Mixins::DefineTestModule::DefineTestClass::ClassMethodsFeature::DefineTestModule::DefineTestClass::AddClassMethods
17
17
  )
18
18
  end
19
19
 
@@ -27,7 +27,7 @@ describe RubyFeatures::Concern::Feature do
27
27
  }.to change{test_class.new.respond_to?(:test_instance_method)}.from(false).to(true)
28
28
 
29
29
  expect(test_class.included_modules).to include(
30
- RubyFeatures::Mixins::DefineTestModule::DefineTestClass::InstanceMethodsFeature::DefineTestModule::DefineTestClass::Include
30
+ RubyFeatures::Mixins::DefineTestModule::DefineTestClass::InstanceMethodsFeature::DefineTestModule::DefineTestClass::AddInstanceMethods
31
31
  )
32
32
  end
33
33
 
@@ -49,7 +49,7 @@ describe RubyFeatures::Concern::Feature do
49
49
  }.to change{test_class.new.test_rewrite_instance_method}.from(2).to(6)
50
50
 
51
51
  expect(test_class.included_modules).to include(
52
- RubyFeatures::Mixins::DefineTestModule::DefineTestClass::RewriteInstanceMethodsFeature::DefineTestModule::DefineTestClass::RewriteInstance
52
+ RubyFeatures::Mixins::DefineTestModule::DefineTestClass::RewriteInstanceMethodsFeature::DefineTestModule::DefineTestClass::RewriteInstanceMethods
53
53
  )
54
54
  end
55
55
 
@@ -71,30 +71,40 @@ describe RubyFeatures::Concern::Feature do
71
71
 
72
72
  it 'should raise error if target already has feature class method' do
73
73
  test_class.class_eval do
74
- def self.existing_class_method; end
74
+ class << self
75
+ def existing_class_method; end
76
+ private
77
+ def existing_private_class_method; end
78
+ end
75
79
  end
76
80
 
77
81
  expect{
78
82
  define_test_feature('existing_class_method') do
79
83
  class_methods do
80
84
  def existing_class_method; end
85
+ private
86
+ def existing_private_class_method; end
81
87
  end
82
88
  end.apply
83
- }.to raise_error(/Tried to extend already existing methods: \[:existing_class_method\]/)
89
+ }.to raise_error(/Tried to add already existing class methods: \[:existing_class_method, :existing_private_class_method\]/)
84
90
  end
85
91
 
86
92
  it 'should raise error if target already has feature instance method' do
87
93
  test_class.class_eval do
88
94
  def existing_instance_method; end
95
+ private
96
+ def existing_private_instance_method; end
89
97
  end
90
98
 
91
99
  expect{
92
100
  define_test_feature('existing_instance_method') do
93
101
  instance_methods do
94
102
  def existing_instance_method; end
103
+ private
104
+ def existing_private_instance_method; end
95
105
  end
96
106
  end.apply
97
- }.to raise_error(/Tried to include already existing methods: \[:existing_instance_method\]/)
107
+ }.to raise_error(/Tried to add already existing instance methods: \[:existing_instance_method, :existing_private_instance_method\]/)
98
108
  end
99
109
 
100
110
  it 'should raise error if target has no feature rewrite instance method' do
@@ -102,9 +112,11 @@ describe RubyFeatures::Concern::Feature do
102
112
  define_test_feature('not_existing_rewrite_instance_method') do
103
113
  rewrite_instance_methods do
104
114
  def not_existing_instance_method; end
115
+ private
116
+ def not_existing_private_instance_method; end
105
117
  end
106
118
  end.apply
107
- }.to raise_error(/Tried to prepend not existing methods: \[:not_existing_instance_method\]/)
119
+ }.to raise_error(/Tried to rewrite not existing instance methods: \[:not_existing_instance_method, :not_existing_private_instance_method\]/)
108
120
  end
109
121
 
110
122
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-features
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Tokarenko