missile_emitter 0.3.13 → 0.3.19
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 +4 -4
- data/Gemfile.lock +27 -12
- data/lib/missile_emitter.rb +7 -46
- data/lib/missile_emitter/configurable.rb +6 -4
- data/lib/missile_emitter/searchable.rb +9 -1
- data/lib/missile_emitter/version.rb +1 -1
- data/missile_emitter.gemspec +3 -1
- metadata +18 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 525f92760c025042f96e1f370ad98633d46305238bc30c7041cc3c2c57fb247a
|
|
4
|
+
data.tar.gz: f4dd1e712152f896653f7c2c9dd45974eda854c44e28047704767a5333091c9a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9593b253dc11e5d109bb2334b4ed2b0b18e3052139359812bc515216c9803cefe07d7e7652c13566839eab4dd0680c4b00292d8f8335c65d7885eb37ba479812
|
|
7
|
+
data.tar.gz: 55572f2c8b620fdaac999df889ff23a5d085e7878ddfae020812ce4849895e6d4dcfbb3c29d8a68d42bb1f9b875c353f74672b826fa314122edb3f94bb1cd4f1
|
data/Gemfile.lock
CHANGED
|
@@ -1,31 +1,46 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
missile_emitter (0.3.
|
|
4
|
+
missile_emitter (0.3.19)
|
|
5
|
+
activesupport
|
|
5
6
|
|
|
6
7
|
GEM
|
|
7
8
|
remote: https://rubygems.org/
|
|
8
9
|
specs:
|
|
10
|
+
activesupport (6.0.3.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, >= 2.2.2)
|
|
9
16
|
coderay (1.1.2)
|
|
17
|
+
concurrent-ruby (1.1.6)
|
|
10
18
|
diff-lcs (1.3)
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
i18n (1.8.2)
|
|
20
|
+
concurrent-ruby (~> 1.0)
|
|
21
|
+
method_source (1.0.0)
|
|
22
|
+
minitest (5.14.1)
|
|
23
|
+
pry (0.13.1)
|
|
24
|
+
coderay (~> 1.1)
|
|
25
|
+
method_source (~> 1.0)
|
|
26
|
+
rake (13.0.1)
|
|
16
27
|
rspec (3.9.0)
|
|
17
28
|
rspec-core (~> 3.9.0)
|
|
18
29
|
rspec-expectations (~> 3.9.0)
|
|
19
30
|
rspec-mocks (~> 3.9.0)
|
|
20
|
-
rspec-core (3.9.
|
|
21
|
-
rspec-support (~> 3.9.
|
|
22
|
-
rspec-expectations (3.9.
|
|
31
|
+
rspec-core (3.9.2)
|
|
32
|
+
rspec-support (~> 3.9.3)
|
|
33
|
+
rspec-expectations (3.9.2)
|
|
23
34
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
24
35
|
rspec-support (~> 3.9.0)
|
|
25
36
|
rspec-mocks (3.9.1)
|
|
26
37
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
27
38
|
rspec-support (~> 3.9.0)
|
|
28
|
-
rspec-support (3.9.
|
|
39
|
+
rspec-support (3.9.3)
|
|
40
|
+
thread_safe (0.3.6)
|
|
41
|
+
tzinfo (1.2.7)
|
|
42
|
+
thread_safe (~> 0.1)
|
|
43
|
+
zeitwerk (2.3.0)
|
|
29
44
|
|
|
30
45
|
PLATFORMS
|
|
31
46
|
ruby
|
|
@@ -34,8 +49,8 @@ DEPENDENCIES
|
|
|
34
49
|
bundler (~> 2.0)
|
|
35
50
|
missile_emitter!
|
|
36
51
|
pry
|
|
37
|
-
rake (~>
|
|
52
|
+
rake (~> 13.0)
|
|
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
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'set'
|
|
2
|
+
|
|
1
3
|
module MissileEmitter
|
|
2
4
|
module Configurable
|
|
3
5
|
|
|
@@ -27,15 +29,15 @@ module MissileEmitter
|
|
|
27
29
|
end
|
|
28
30
|
end
|
|
29
31
|
|
|
30
|
-
# 获取所有配置项名称:Klass
|
|
32
|
+
# 获取所有配置项名称:Configurable.option_names_for(Klass) ---> [:logo, copyright, ...]
|
|
31
33
|
define_singleton_method :option_names_for do |klass|
|
|
32
34
|
mapping.fetch klass, []
|
|
33
35
|
end
|
|
34
36
|
|
|
35
|
-
# 获取所有配置:Klass
|
|
37
|
+
# 获取所有配置:Configurable.options_for(Klass) ---> {logo: '', copyright: '', ...}
|
|
36
38
|
define_singleton_method :options_for do |klass|
|
|
37
|
-
|
|
38
|
-
result[key] = send key
|
|
39
|
+
option_names_for(klass).each_with_object({}) do |key, result|
|
|
40
|
+
result[key] = klass.send key
|
|
39
41
|
end
|
|
40
42
|
end
|
|
41
43
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
|
|
1
3
|
module MissileEmitter
|
|
2
4
|
module Searchable
|
|
3
5
|
|
|
@@ -9,14 +11,20 @@ module MissileEmitter
|
|
|
9
11
|
(conditions[klass] ||= {}.with_indifferent_access)[key] = block
|
|
10
12
|
end
|
|
11
13
|
|
|
14
|
+
has_underline_method = Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7.0')
|
|
15
|
+
|
|
12
16
|
define_method :search do |hash|
|
|
13
17
|
hash.reduce all do |relation, (key, value)|
|
|
14
18
|
next relation if value.blank? # ignore empty value
|
|
15
19
|
|
|
16
20
|
if filter = conditions.fetch(self, {})[key]
|
|
21
|
+
# Inside the scope block, You can get value through calling the _ method
|
|
17
22
|
relation.extending do
|
|
18
|
-
# Just for fun :)
|
|
23
|
+
# Just for fun :)
|
|
19
24
|
define_method(:_) { value }
|
|
25
|
+
# With ruby >= 2.7 you can use _1 instead of _
|
|
26
|
+
# Polyfill for the earlier version
|
|
27
|
+
alias_method :_1, :_ unless has_underline_method
|
|
20
28
|
end.instance_exec(value, &filter)
|
|
21
29
|
elsif column_names.include?(key.to_s)
|
|
22
30
|
relation.where key => value
|
data/missile_emitter.gemspec
CHANGED
|
@@ -29,7 +29,9 @@ Gem::Specification.new do |spec|
|
|
|
29
29
|
spec.require_paths = ["lib"]
|
|
30
30
|
|
|
31
31
|
spec.add_development_dependency "bundler", "~> 2.0"
|
|
32
|
-
spec.add_development_dependency "rake", "~>
|
|
32
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
33
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
34
34
|
spec.add_development_dependency "pry"
|
|
35
|
+
|
|
36
|
+
spec.add_dependency "activesupport"
|
|
35
37
|
end
|
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.19
|
|
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-
|
|
11
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -30,14 +30,14 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
33
|
+
version: '13.0'
|
|
34
34
|
type: :development
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
40
|
+
version: '13.0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: rspec
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -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
|