super_module 1.4.0 → 1.4.1

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
  SHA256:
3
- metadata.gz: a4faa73d0b49aef392b5dd1c26df10e4fc7ae5f9c528284503cd68df38c2381b
4
- data.tar.gz: 9c48055a31b17ae2cdd554314cc3dbbf4d10e6eb2a93d4f21636663ce0f0a6c5
3
+ metadata.gz: 192ef511f9395d9d90d7110a154602a4c62a47c5287cfaf9662456be09c84712
4
+ data.tar.gz: c4233e47af1355abff03878070f2916175aa1c399deb3a2e696b5fb18351dbef
5
5
  SHA512:
6
- metadata.gz: 37e9470e3ebe8977cf24425169ac7976304ba4d4eb1c0ca8069fa761813184d24e182235cc57ae01674f09189e22fe2681bd0b3a580e23aff50e323cc47ef435
7
- data.tar.gz: 998e4a95be965413b20f49d2dad072a3458b61fd13e34eb33db601bd96ee3f7581c015ccb0e8872b8f3ef329a585dea902cccc165ac7921e58c503a6b2396892
6
+ metadata.gz: f1cd9c156c81762b287a4eb67b1b0b1bff5a27cd0325e3baef9b0fe2da7b77a3ecfb948c21ed99c295e6c020858c0c2c0a507dd8c9c232f80b6abc07b539cf17
7
+ data.tar.gz: 11973559c530a77b64f1d04bdd15964f73549f1b3a3f7fc93d694b503f35cfcacbdacbbf74602b2ea371b02d70137ab26b663756e7ab4d753bb19f0910df752f
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.4.1
4
+
5
+ - Pauses singleton method recording inside a super_module_included block to avoid replaying on submodules
6
+
3
7
  ## 1.4.0
4
8
 
5
9
  - Support aliased methods
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # <img src="https://raw.githubusercontent.com/AndyObtiva/super_module/master/SuperModule.jpg" alt="SuperModule" align="left" height="50" /> &nbsp; SuperModule 1.3
1
+ # <img src="https://raw.githubusercontent.com/AndyObtiva/super_module/master/SuperModule.jpg" alt="SuperModule" align="left" height="50" /> &nbsp; SuperModule 1.4.0
2
2
  [![Gem Version](https://badge.fury.io/rb/super_module.svg)](http://badge.fury.io/rb/super_module)
3
3
  [![Build Status](https://api.travis-ci.org/AndyObtiva/super_module.svg?branch=master)](https://travis-ci.org/AndyObtiva/super_module)
4
4
  [![Coverage Status](https://coveralls.io/repos/AndyObtiva/super_module/badge.svg?branch=master)](https://coveralls.io/r/AndyObtiva/super_module?branch=master)
@@ -104,7 +104,7 @@ In other words, [SuperModule](https://rubygems.org/gems/super_module) furthers R
104
104
 
105
105
  <b>Using [Bundler](http://bundler.io/)</b>
106
106
 
107
- Add the following to Gemfile: <pre>gem 'super_module', '1.4.0'</pre>
107
+ Add the following to Gemfile: <pre>gem 'super_module', '1.4.1'</pre>
108
108
 
109
109
  And run the following command: <pre>bundle</pre>
110
110
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.4.0
1
+ 1.4.1
@@ -28,7 +28,15 @@ module SuperModule
28
28
  def included(base)
29
29
  __define_super_module_singleton_methods(base)
30
30
  __invoke_module_body_method_calls(base)
31
- super_module_included.each {|block| block.call(base)}
31
+ super_module_included.each do |block|
32
+ self.__inside_super_module_included = true
33
+ base.__inside_super_module_included = true
34
+ block.binding.receiver.__inside_super_module_included = true
35
+ block.call(base)
36
+ block.binding.receiver.__inside_super_module_included = false
37
+ base.__inside_super_module_included = false
38
+ self.__inside_super_module_included = false
39
+ end
32
40
  if base.ancestors.include?(SuperModule) && !base.is_a?(Class)
33
41
  super_module_included.reverse.each do |block|
34
42
  base.super_module_included.unshift(block)
@@ -5,6 +5,8 @@ module SuperModule
5
5
  @__super_module_singleton_methods_excluded_from_call_recording ||= [
6
6
  :__record_method_call,
7
7
  :__method_signature,
8
+ :__inside_super_module_included?,
9
+ :__inside_super_module_included=,
8
10
  ]
9
11
  end
10
12
 
@@ -17,10 +19,18 @@ module SuperModule
17
19
  end
18
20
 
19
21
  def __record_method_call(method_name, *args, &block)
20
- return if self.is_a?(Class)
22
+ return if self.is_a?(Class) || __inside_super_module_included?
21
23
  __module_body_method_calls << [method_name, args, block]
22
24
  end
23
25
 
26
+ def __inside_super_module_included?
27
+ @__inside_super_module_included
28
+ end
29
+
30
+ def __inside_super_module_included=(value)
31
+ @__inside_super_module_included = !!value
32
+ end
33
+
24
34
  def __all_module_body_method_calls_in_definition_order
25
35
  ancestor_module_body_method_calls = included_super_modules.map(&:__module_body_method_calls).flatten(1)
26
36
  all_module_body_method_calls = __module_body_method_calls + ancestor_module_body_method_calls
@@ -54,11 +54,12 @@ module SuperModule
54
54
  end
55
55
 
56
56
  def __singleton_method_definition_regex(method_name)
57
+ method_name = Regexp.escape(method_name.to_s)
57
58
  /(public|protected|private)?(send)?[ \t(:"']*def(ine_method)?[ \t,:"']+(self\.)?#{method_name}\)?[ \tdo{(|]*([^\n)|;]*)?[ \t)|;]*/m
58
59
  end
59
60
 
60
61
  def __singleton_method_args(method_name, method_body)
61
- method_arg_match = method_body.match(__singleton_method_definition_regex(method_name)).to_a[5]
62
+ method_body.match(__singleton_method_definition_regex(method_name)).to_a[5]
62
63
  end
63
64
 
64
65
  def __singleton_method_access_level(method_name)
@@ -106,6 +107,8 @@ module SuperModule
106
107
  base.extend(SuperModule::V1::ModuleBodyMethodCallRecorder) unless base.is_a?(SuperModule::V1::ModuleBodyMethodCallRecorder)
107
108
  base.singleton_method_added(:__method_signature)
108
109
  base.singleton_method_added(:__record_method_call)
110
+ base.singleton_method_added(:__inside_super_module_included?)
111
+ base.singleton_method_added(:__inside_super_module_included=)
109
112
  end
110
113
  end
111
114
  end
@@ -19,12 +19,6 @@ end
19
19
  module V1::SummarizedActiveModel
20
20
  include SuperModule
21
21
 
22
- super_module_included do |klass|
23
- if klass.name.split(/::/).last.start_with?('Fake')
24
- klass.extend(FakeClassMethods1)
25
- end
26
- end
27
-
28
22
  module FakeClassMethods1
29
23
  def fake_summary
30
24
  'This is a fake summary.'
@@ -43,7 +37,19 @@ module V1::SummarizedActiveModel
43
37
  def summary
44
38
  validations.flatten.map(&:to_s).join("/")
45
39
  end
40
+
41
+ def only_call_in_super_module_included
42
+ raise 'Error' unless self == ::V1::SummarizedActiveModel
43
+ end
46
44
  end
45
+
46
+ super_module_included do |klass|
47
+ if klass.name.split(/::/).last.start_with?('Fake')
48
+ klass.extend(FakeClassMethods1)
49
+ end
50
+ only_call_in_super_module_included # should not get recorded for submodules/subclasses
51
+ end
52
+
47
53
  end
48
54
 
49
55
  module V1::ExtraSummarizedActiveModel
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: super_module 1.4.0 ruby lib
5
+ # stub: super_module 1.4.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "super_module".freeze
9
- s.version = "1.4.0"
9
+ s.version = "1.4.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Andy Maleh".freeze]
14
- s.date = "2020-04-06"
14
+ s.date = "2020-04-23"
15
15
  s.description = "SuperModule allows defining class methods and method invocations the same way a super class does without using def included(base). This also succeeds ActiveSupport::Concern by offering lighter syntax".freeze
16
16
  s.extra_rdoc_files = [
17
17
  "CHANGELOG.md",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super_module
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-06 00:00:00.000000000 Z
11
+ date: 2020-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: method_source