missile_emitter 0.3.16 → 0.3.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +17 -2
- data/lib/missile_emitter.rb +7 -46
- data/lib/missile_emitter/version.rb +1 -1
- data/missile_emitter.gemspec +2 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '09f1b2c72945a8304531759d552b5c3efb9c988ce6468acefd896012b6122bea'
|
4
|
+
data.tar.gz: 1bff41956032c30ec90dd05f0aa3fed0f3a82deead94fa3e71f36166b0abaedb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5db328b35cd81e444845841e204ddca067e78f5c89f9dc8279699d59cb59e2b6487c52aea1fa104454205e489e63c6cb7cece93a650cb2321ea972674898406
|
7
|
+
data.tar.gz: 7b5a4f24e42d9881accece9686f4ab02d397c8a4fae0c73c9cb8aed3633d91ed58a081d01578fd872c1972a053bbf75ab1e5efd8303432eb28d0dfdf8e656b0e
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
missile_emitter (0.3.
|
4
|
+
missile_emitter (0.3.17)
|
5
|
+
activesupport
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
8
9
|
specs:
|
10
|
+
activesupport (6.0.2.1)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 0.7, < 2)
|
13
|
+
minitest (~> 5.1)
|
14
|
+
tzinfo (~> 1.1)
|
15
|
+
zeitwerk (~> 2.2)
|
9
16
|
coderay (1.1.2)
|
17
|
+
concurrent-ruby (1.1.5)
|
10
18
|
diff-lcs (1.3)
|
19
|
+
i18n (1.8.2)
|
20
|
+
concurrent-ruby (~> 1.0)
|
11
21
|
method_source (0.9.2)
|
22
|
+
minitest (5.14.0)
|
12
23
|
pry (0.12.2)
|
13
24
|
coderay (~> 1.1.0)
|
14
25
|
method_source (~> 0.9.0)
|
@@ -26,6 +37,10 @@ GEM
|
|
26
37
|
diff-lcs (>= 1.2.0, < 2.0)
|
27
38
|
rspec-support (~> 3.9.0)
|
28
39
|
rspec-support (3.9.2)
|
40
|
+
thread_safe (0.3.6)
|
41
|
+
tzinfo (1.2.6)
|
42
|
+
thread_safe (~> 0.1)
|
43
|
+
zeitwerk (2.2.2)
|
29
44
|
|
30
45
|
PLATFORMS
|
31
46
|
ruby
|
@@ -38,4 +53,4 @@ DEPENDENCIES
|
|
38
53
|
rspec (~> 3.0)
|
39
54
|
|
40
55
|
BUNDLED WITH
|
41
|
-
2.1.
|
56
|
+
2.1.4
|
data/lib/missile_emitter.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "active_support/core_ext/string"
|
1
2
|
require "missile_emitter/version"
|
2
3
|
require "missile_emitter/battle_field"
|
3
4
|
|
@@ -16,11 +17,11 @@ module MissileEmitter
|
|
16
17
|
attr_accessor :mapping
|
17
18
|
|
18
19
|
def exec(namespace, &block)
|
19
|
-
raise Error
|
20
|
+
raise Error, '需要提供代码块' unless block
|
20
21
|
|
21
22
|
context = block.binding.receiver
|
22
23
|
|
23
|
-
raise Error
|
24
|
+
raise Error, '只能再具名模块中调用' unless context.instance_of?(Module) && context.name
|
24
25
|
|
25
26
|
mimic_method context, namespace: namespace
|
26
27
|
|
@@ -32,62 +33,22 @@ module MissileEmitter
|
|
32
33
|
def mimic_method(context, namespace: true)
|
33
34
|
path = context.name
|
34
35
|
|
35
|
-
ns = deconstantize
|
36
|
-
name = demodulize
|
36
|
+
ns = path.deconstantize
|
37
|
+
name = path.demodulize
|
37
38
|
|
38
39
|
# 处理嵌套模块
|
39
|
-
container = !ns.empty? && namespace ? constantize
|
40
|
+
container = !ns.empty? && namespace ? ns.constantize : Kernel
|
40
41
|
action = container == Kernel ? 'define_method' : 'define_singleton_method'
|
41
42
|
|
42
43
|
container.send action, name do |*args, &missile|
|
43
44
|
klass = missile.binding.receiver
|
44
45
|
battle_field = BattleField.new klass, *args, MissileEmitter.mapping[context]
|
45
|
-
battle_field.emit!
|
46
|
+
battle_field.emit!(&missile)
|
46
47
|
|
47
48
|
context
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
def demodulize(path)
|
52
|
-
path = path.to_s
|
53
|
-
|
54
|
-
if i = path.rindex("::")
|
55
|
-
path[(i + 2)..-1]
|
56
|
-
else
|
57
|
-
path
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
def deconstantize(path)
|
62
|
-
path.to_s[0, path.rindex("::") || 0]
|
63
|
-
end
|
64
|
-
|
65
|
-
def constantize(camel_cased_word)
|
66
|
-
names = camel_cased_word.split("::")
|
67
|
-
|
68
|
-
Object.const_get(camel_cased_word) if names.empty?
|
69
|
-
|
70
|
-
names.shift if names.size > 1 && names.first.empty?
|
71
|
-
|
72
|
-
names.inject(Object) do |constant, name|
|
73
|
-
if constant == Object
|
74
|
-
constant.const_get(name)
|
75
|
-
else
|
76
|
-
candidate = constant.const_get(name)
|
77
|
-
next candidate if constant.const_defined?(name, false)
|
78
|
-
next candidate unless Object.const_defined?(name)
|
79
|
-
|
80
|
-
constant = constant.ancestors.inject(constant) do |const, ancestor|
|
81
|
-
break const if ancestor == Object
|
82
|
-
break ancestor if ancestor.const_defined?(name, false)
|
83
|
-
const
|
84
|
-
end
|
85
|
-
|
86
|
-
constant.const_get(name, false)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
52
|
end
|
92
53
|
|
93
54
|
end
|
data/missile_emitter.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: missile_emitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jerry Chen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: 'Ruby元编程小工具,让你能在类定义(class definition)级别触发 method_missing 事件,同时不用担心潜在的命名冲突。 '
|
70
84
|
email:
|
71
85
|
- code@coding-class.com
|
@@ -115,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
115
129
|
- !ruby/object:Gem::Version
|
116
130
|
version: '0'
|
117
131
|
requirements: []
|
118
|
-
rubygems_version: 3.0.
|
132
|
+
rubygems_version: 3.0.3
|
119
133
|
signing_key:
|
120
134
|
specification_version: 4
|
121
135
|
summary: Ruby元编程辅助工具
|