kungfuig 0.5.8 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -0
- data/.rubocop_todo.yml +30 -39
- data/kungfuig.gemspec +2 -2
- data/lib/kungfuig/aspector.rb +29 -28
- data/lib/kungfuig/jobber.rb +3 -7
- data/lib/kungfuig/prepender.rb +156 -0
- data/lib/kungfuig/version.rb +1 -1
- data/lib/kungfuig.rb +8 -45
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d7f9a97f500edb6d6bf35a4cb678989571aac2a
|
4
|
+
data.tar.gz: 7b15f8867b76dd007cfda00c17275bb4a1d45057
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b7646e393a547a7916291e4fd3e2a4d22fd6d1807cb6f5c67a9b3d2bdaccbcc817ed661aed83a2ccf7cee08b46ec09b3689d4317662755defacb8489ceb2a89
|
7
|
+
data.tar.gz: 2907858a439b6818f99b5fb783d3603bb2fe7ebd9bf0dd2c1637de93cc2a07cb23e4e9b53319ba89415e89efed67de8b16ad5ec0906c0e633607584a6006cdfc
|
data/.rubocop.yml
CHANGED
@@ -10,6 +10,11 @@ Style/AsciiComments:
|
|
10
10
|
- 'lib/**/*'
|
11
11
|
- 'spec/**/*'
|
12
12
|
|
13
|
+
Style/Documentation:
|
14
|
+
Exclude:
|
15
|
+
- 'lib/**/*'
|
16
|
+
- 'spec/**/*'
|
17
|
+
|
13
18
|
Style/RaiseArgs:
|
14
19
|
Exclude:
|
15
20
|
- 'lib/**/*'
|
@@ -18,3 +23,8 @@ Style/SpecialGlobalVars:
|
|
18
23
|
Exclude:
|
19
24
|
- 'lib/**/*'
|
20
25
|
- 'spec/**/*'
|
26
|
+
|
27
|
+
Style/MultilineBlockChain:
|
28
|
+
Exclude:
|
29
|
+
- 'lib/**/*'
|
30
|
+
- 'spec/**/*'
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2016-
|
3
|
+
# on 2016-04-22 13:12:24 +0200 using RuboCop version 0.39.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -13,37 +13,37 @@ Lint/UnusedBlockArgument:
|
|
13
13
|
Exclude:
|
14
14
|
- 'features/step_definitions/kungfuig_steps.rb'
|
15
15
|
|
16
|
-
# Offense count:
|
17
|
-
Lint/UselessAssignment:
|
18
|
-
Exclude:
|
19
|
-
- 'lib/kungfuig.rb'
|
20
|
-
|
21
|
-
# Offense count: 2
|
16
|
+
# Offense count: 10
|
22
17
|
Metrics/AbcSize:
|
23
|
-
Max:
|
18
|
+
Max: 41
|
24
19
|
|
25
|
-
# Offense count:
|
20
|
+
# Offense count: 4
|
26
21
|
Metrics/CyclomaticComplexity:
|
27
|
-
Max:
|
22
|
+
Max: 12
|
28
23
|
|
29
|
-
# Offense count:
|
24
|
+
# Offense count: 77
|
30
25
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes.
|
31
26
|
# URISchemes: http, https
|
32
27
|
Metrics/LineLength:
|
33
|
-
Max:
|
28
|
+
Max: 174
|
34
29
|
|
35
|
-
# Offense count:
|
30
|
+
# Offense count: 6
|
36
31
|
# Configuration parameters: CountComments.
|
37
32
|
Metrics/MethodLength:
|
38
|
-
Max:
|
33
|
+
Max: 24
|
39
34
|
|
40
|
-
# Offense count:
|
35
|
+
# Offense count: 2
|
36
|
+
Metrics/PerceivedComplexity:
|
37
|
+
Max: 8
|
38
|
+
|
39
|
+
# Offense count: 3
|
41
40
|
# Cop supports --auto-correct.
|
42
41
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
43
42
|
# SupportedStyles: prefer_alias, prefer_alias_method
|
44
43
|
Style/Alias:
|
45
44
|
Exclude:
|
46
45
|
- 'lib/kungfuig.rb'
|
46
|
+
- 'lib/kungfuig/prepender.rb'
|
47
47
|
|
48
48
|
# Offense count: 4
|
49
49
|
# Cop supports --auto-correct.
|
@@ -65,22 +65,7 @@ Style/BracesAroundHashParameters:
|
|
65
65
|
Exclude:
|
66
66
|
- 'features/step_definitions/kungfuig_steps.rb'
|
67
67
|
|
68
|
-
# Offense count:
|
69
|
-
Style/Documentation:
|
70
|
-
Exclude:
|
71
|
-
- 'spec/**/*'
|
72
|
-
- 'test/**/*'
|
73
|
-
- 'lib/kungfuig.rb'
|
74
|
-
|
75
|
-
# Offense count: 1
|
76
|
-
# Cop supports --auto-correct.
|
77
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
78
|
-
# SupportedStyles: empty_lines, no_empty_lines
|
79
|
-
Style/EmptyLinesAroundBlockBody:
|
80
|
-
Exclude:
|
81
|
-
- 'lib/kungfuig.rb'
|
82
|
-
|
83
|
-
# Offense count: 10
|
68
|
+
# Offense count: 21
|
84
69
|
# Cop supports --auto-correct.
|
85
70
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
86
71
|
# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
|
@@ -98,12 +83,6 @@ Style/MutableConstant:
|
|
98
83
|
Exclude:
|
99
84
|
- 'lib/kungfuig/version.rb'
|
100
85
|
|
101
|
-
# Offense count: 6
|
102
|
-
# Configuration parameters: SupportedStyles.
|
103
|
-
# SupportedStyles: compact, exploded
|
104
|
-
Style/RaiseArgs:
|
105
|
-
EnforcedStyle: compact
|
106
|
-
|
107
86
|
# Offense count: 6
|
108
87
|
# Cop supports --auto-correct.
|
109
88
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
@@ -119,16 +98,28 @@ Style/SpaceAroundOperators:
|
|
119
98
|
Exclude:
|
120
99
|
- 'features/support/env.rb'
|
121
100
|
|
122
|
-
# Offense count:
|
101
|
+
# Offense count: 4
|
102
|
+
# Cop supports --auto-correct.
|
103
|
+
Style/SpaceBeforeSemicolon:
|
104
|
+
Exclude:
|
105
|
+
- 'lib/kungfuig/prepender.rb'
|
106
|
+
|
107
|
+
# Offense count: 20
|
123
108
|
# Cop supports --auto-correct.
|
124
109
|
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
|
125
110
|
# SupportedStyles: space, no_space
|
126
111
|
Style/SpaceInsideHashLiteralBraces:
|
127
112
|
Enabled: false
|
128
113
|
|
129
|
-
# Offense count:
|
114
|
+
# Offense count: 12
|
130
115
|
# Cop supports --auto-correct.
|
131
116
|
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
|
132
117
|
# SupportedStyles: single_quotes, double_quotes
|
133
118
|
Style/StringLiterals:
|
134
119
|
Enabled: false
|
120
|
+
|
121
|
+
# Offense count: 2
|
122
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
123
|
+
# SupportedStyles: snake_case, camelCase
|
124
|
+
Style/VariableName:
|
125
|
+
Enabled: false
|
data/kungfuig.gemspec
CHANGED
@@ -28,9 +28,9 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'rake', '~> 10.0'
|
29
29
|
spec.add_development_dependency 'pry', '~> 0.10'
|
30
30
|
|
31
|
-
spec.add_development_dependency 'rspec', '~>
|
31
|
+
spec.add_development_dependency 'rspec', '~> 3'
|
32
32
|
spec.add_development_dependency 'cucumber', '~> 1.3'
|
33
33
|
spec.add_development_dependency 'yard', '~> 0'
|
34
34
|
|
35
|
-
spec.add_development_dependency 'rspec-sidekiq', '~>
|
35
|
+
spec.add_development_dependency 'rspec-sidekiq', '~> 2'
|
36
36
|
end
|
data/lib/kungfuig/aspector.rb
CHANGED
@@ -4,14 +4,22 @@ module Kungfuig
|
|
4
4
|
# Helper methods
|
5
5
|
class H
|
6
6
|
def value_to_method_list klazz, values_inc, values_exc
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
# FIXME MOVE JOKER HANDLING INTO PREPENDER !!!!
|
8
|
+
if klazz.is_a?(Module)
|
9
|
+
[values_inc, values_exc].map do |v|
|
10
|
+
v = [*v].map(&:to_sym)
|
11
|
+
case
|
12
|
+
when v.empty? then []
|
13
|
+
when v.include?('*'), v.include?(:'*') then klazz.instance_methods(false)
|
14
|
+
else klazz.instance_methods & v
|
15
|
+
end
|
16
|
+
end.reduce(&:-) - klazz.instance_methods(false).select { |m| m.to_s.start_with?('to_') }
|
17
|
+
else
|
18
|
+
# NOT YET IMPLEMENTED FIXME MOVE TO PREPENDER
|
19
|
+
[values_inc, values_exc].map do |v|
|
20
|
+
[*v].map(&:to_sym)
|
21
|
+
end.reduce(&:-)
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
25
|
def remap_hash_for_easy_iteration hash
|
@@ -27,41 +35,34 @@ module Kungfuig
|
|
27
35
|
m, k = string.split('#').reverse
|
28
36
|
(k ? Kernel.const_get(k).method(m) : method(m)).to_proc
|
29
37
|
end
|
38
|
+
|
39
|
+
def try_to_class name
|
40
|
+
Kernel.const_defined?(name.to_s) ? Kernel.const_get(name.to_s) : name
|
41
|
+
end
|
30
42
|
end
|
31
43
|
|
32
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
33
|
-
# rubocop:disable Metrics/MethodLength
|
34
44
|
def attach(to, before: nil, after: nil, exclude: nil)
|
35
|
-
klazz = begin
|
36
|
-
case to
|
37
|
-
when Class then to # got a class! wow, somebody has the documentation read
|
38
|
-
when String then Kernel.const_get(to) # we are ready to get a class name
|
39
|
-
when Symbol then Kernel.const_get(to.to_s)
|
40
|
-
else class << to; self; end # attach to klazz’s eigenclass if object given
|
41
|
-
end
|
42
|
-
rescue => e
|
43
|
-
raise ArgumentError, "Unable to attach to #{to}. I need a valid class/method name!\nOriginal exception: #{e.message}"
|
44
|
-
end
|
45
|
-
|
46
45
|
raise ArgumentError, "Trying to attach nothing to #{klazz}##{to}. I need a block!" unless block_given?
|
47
|
-
|
46
|
+
|
48
47
|
cb = Proc.new
|
49
48
|
|
49
|
+
klazz = case to
|
50
|
+
when Module then to # got a class! wow, somebody has the documentation read
|
51
|
+
when String, Symbol then H.new.try_to_class(to) # we are ready to get a class name
|
52
|
+
else class << to; self; end # attach to klazz’s eigenclass if object given
|
53
|
+
end
|
54
|
+
|
50
55
|
H.new.value_to_method_list(klazz, before, exclude).each do |m|
|
51
|
-
|
52
|
-
klazz.aspect(m, false, &cb)
|
56
|
+
Kungfuig::Prepender.new(to, m).before(&cb)
|
53
57
|
end unless before.nil?
|
54
58
|
|
55
59
|
H.new.value_to_method_list(klazz, after, exclude).each do |m|
|
56
|
-
|
57
|
-
klazz.aspect(m, true, &cb)
|
60
|
+
Kungfuig::Prepender.new(to, m).after(&cb)
|
58
61
|
end unless after.nil?
|
59
62
|
|
60
63
|
klazz.aspects
|
61
64
|
end
|
62
65
|
module_function :attach
|
63
|
-
# rubocop:enable Metrics/MethodLength
|
64
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
65
66
|
|
66
67
|
# 'Test':
|
67
68
|
# after:
|
data/lib/kungfuig/jobber.rb
CHANGED
@@ -23,9 +23,7 @@ module Kungfuig
|
|
23
23
|
)
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
# rubocop:disable Metrics/MethodLength
|
28
|
-
def bottleneck(receiver, method, result, *args)
|
26
|
+
def bottleneck(method:nil, receiver:nil, result:nil, args:nil, **_)
|
29
27
|
respond_to = ->(m, r) { r.respond_to? m.to_sym }
|
30
28
|
r = case receiver
|
31
29
|
when Hash, Array, String then receiver
|
@@ -39,14 +37,12 @@ module Kungfuig
|
|
39
37
|
|
40
38
|
Kernel.const_get(@hash[receiver_class.name][method]).perform_async(r, method, result, *args)
|
41
39
|
rescue => e
|
42
|
-
Kungfuig.✍([
|
40
|
+
Kungfuig.✍(receiver: [
|
43
41
|
"Fail [#{e.message}]",
|
44
42
|
*e.backtrace.unshift("Backtrace:").join("#{$/}⮩ "),
|
45
43
|
"while #{receiver}"
|
46
|
-
].join($/), method, result,
|
44
|
+
].join($/), method: method, result: result, args: args)
|
47
45
|
end
|
48
|
-
# rubocop:enable Metrics/MethodLength
|
49
|
-
# rubocop:enable Metrics/AbcSize
|
50
46
|
end
|
51
47
|
end
|
52
48
|
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
module Kungfuig
|
2
|
+
module I★I
|
3
|
+
end
|
4
|
+
|
5
|
+
LAMBDA = lambda do |λ, e, **hash|
|
6
|
+
begin
|
7
|
+
Kungfuig::Prepender.error! e, **hash
|
8
|
+
λ[:on_error].call(e, **hash) if λ[:on_error]
|
9
|
+
rescue => e
|
10
|
+
Kungfuig::Prepender.error! e, reason: :on_error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Prepender
|
15
|
+
class MalformedTarget < StandardError
|
16
|
+
def initialize msg, args
|
17
|
+
super "#{msg}. Target arguments: [#{args.inspect}]."
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
AGRESSIVE_ERRORS = true
|
22
|
+
|
23
|
+
class << self
|
24
|
+
def errors
|
25
|
+
@errors ||= []
|
26
|
+
end
|
27
|
+
|
28
|
+
def error! e, **hash
|
29
|
+
errors << [e, hash]
|
30
|
+
end
|
31
|
+
|
32
|
+
def anteponer *args
|
33
|
+
raise MalformedTarget.new "Factory requires a block; use Prepender#new for more accurate tuning", args unless block_given?
|
34
|
+
Prepender.new(*args, &Proc.new)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
attr_reader :method, :receiver, :options, :λ
|
39
|
+
|
40
|
+
# Parameters might be:
|
41
|
+
# • 1
|
42
|
+
# — method instance
|
43
|
+
# — string in form "Class#method"
|
44
|
+
# • 2
|
45
|
+
# — class (String, Symbol or Class), method name (String, Symbol)
|
46
|
+
# — instance (Object), method name (String, Symbol)
|
47
|
+
def initialize *args, **params
|
48
|
+
@λ = { before: nil, after: nil, on_hook: nil }
|
49
|
+
@klazz, @method, @receiver = case args.size
|
50
|
+
when 1
|
51
|
+
case args.first
|
52
|
+
when Method then [(class << args.first.receiver ; self ; end), args.first.name, args.first.receiver]
|
53
|
+
when UnboundMethod then [args.first.owner, args.first.name]
|
54
|
+
when String
|
55
|
+
k, m = args.first.split('#')
|
56
|
+
[k, m && m.to_sym]
|
57
|
+
end
|
58
|
+
when 2
|
59
|
+
case args.first
|
60
|
+
when Module, String then [args.first, args.last.to_sym]
|
61
|
+
when Symbol then [args.first.to_s.split('_').map(&:capitalize).join, args.last.to_sym]
|
62
|
+
else
|
63
|
+
[(class << args.first ; self ; end), args.last.to_sym, args.first]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
@options = params
|
68
|
+
after(Proc.new) if block_given? # assign the block to after by default
|
69
|
+
|
70
|
+
raise MalformedTarget.new "Unable to lookup class", args unless @klazz
|
71
|
+
raise MalformedTarget.new "Unable to lookup method", args unless @method
|
72
|
+
|
73
|
+
postpone_hook
|
74
|
+
end
|
75
|
+
|
76
|
+
def before λ = nil
|
77
|
+
@λ[__callee__] = λ || (block_given? ? Proc.new : nil)
|
78
|
+
self
|
79
|
+
end
|
80
|
+
alias_method :after, :before
|
81
|
+
alias_method :on_hook, :before
|
82
|
+
alias_method :on_error, :before
|
83
|
+
|
84
|
+
protected
|
85
|
+
|
86
|
+
def klazz
|
87
|
+
return @klazz if @klazz.is_a?(Module)
|
88
|
+
@klazz = Kernel.const_get(@klazz) if Kernel.const_defined?(@klazz)
|
89
|
+
@klazz
|
90
|
+
end
|
91
|
+
|
92
|
+
def ready?
|
93
|
+
@receiver && @receiver.respond_to?(@method) ||
|
94
|
+
klazz.is_a?(Module) && klazz.instance_methods.include?(@method)
|
95
|
+
end
|
96
|
+
|
97
|
+
def to_hash
|
98
|
+
{
|
99
|
+
klazz: klazz,
|
100
|
+
method: @method,
|
101
|
+
lambdas: @λ
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
def hook
|
106
|
+
status = {}
|
107
|
+
|
108
|
+
λ = (hash = to_hash).delete(:lambdas)
|
109
|
+
|
110
|
+
p = Module.new do
|
111
|
+
include Kungfuig::I★I
|
112
|
+
define_method(hash[:method]) do |*args, **params, &cb|
|
113
|
+
before_params = hash.merge(receiver: self, args: args, params: params, cb: cb)
|
114
|
+
begin
|
115
|
+
λ[:before].call(**before_params) if λ[:before]
|
116
|
+
rescue => e
|
117
|
+
status[:before] = e
|
118
|
+
LAMBDA.call λ, e, **hash
|
119
|
+
end
|
120
|
+
|
121
|
+
super(*args, **params, &cb).tap do |result|
|
122
|
+
begin
|
123
|
+
λ[:after].call(**before_params.merge(result: result)) if λ[:after]
|
124
|
+
rescue => e
|
125
|
+
status[:after] = e
|
126
|
+
LAMBDA.call λ, e, **hash
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
klazz.send(:include, Kungfuig) unless klazz.ancestors.include? Kungfuig
|
132
|
+
klazz.send(:prepend, p)
|
133
|
+
|
134
|
+
rescue => e
|
135
|
+
status[:rescued] = e
|
136
|
+
raise MalformedTarget.new e.message, "#{@klazz}##{@method}" if AGRESSIVE_ERRORS
|
137
|
+
ensure
|
138
|
+
begin
|
139
|
+
λ[:on_hook].call(status) if λ[:on_hook]
|
140
|
+
rescue => e
|
141
|
+
LAMBDA.call λ, e, reason: :on_hook
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def postpone_hook
|
146
|
+
return hook if ready?
|
147
|
+
|
148
|
+
TracePoint.new(:end) do |tp|
|
149
|
+
if tp.self.name == @klazz && ready?
|
150
|
+
hook
|
151
|
+
tp.disable
|
152
|
+
end
|
153
|
+
end.enable
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
data/lib/kungfuig/version.rb
CHANGED
data/lib/kungfuig.rb
CHANGED
@@ -4,16 +4,13 @@ require 'hashie'
|
|
4
4
|
require 'kungfuig/version'
|
5
5
|
require 'kungfuig/color'
|
6
6
|
require 'kungfuig/aspector'
|
7
|
+
require 'kungfuig/prepender'
|
7
8
|
|
8
9
|
module Kungfuig
|
9
|
-
ASPECT_PREFIX = '♻_'.freeze
|
10
|
-
ASPECT_TEMPLATE = -> { %i(after before).map { |k| [k, []] }.to_h }
|
11
|
-
|
12
10
|
MX = Mutex.new
|
13
11
|
|
14
|
-
# rubocop:disable Style/VariableName
|
15
12
|
# rubocop:disable Style/MethodName
|
16
|
-
def ✍(receiver, method, result,
|
13
|
+
def ✍(receiver: nil, method: nil, result: nil, args: nil, **params)
|
17
14
|
require 'logger'
|
18
15
|
@✍ ||= Kernel.const_defined?('Rails') && Rails.logger || Logger.new($stdout)
|
19
16
|
message = receiver.is_a?(String) ? "#{receiver} | #{method}" : "#{receiver.class}##{method}"
|
@@ -23,9 +20,7 @@ module Kungfuig
|
|
23
20
|
end
|
24
21
|
module_function :✍
|
25
22
|
# rubocop:enable Style/MethodName
|
26
|
-
# rubocop:enable Style/VariableName
|
27
23
|
|
28
|
-
# rubocop:disable Metrics/MethodLength
|
29
24
|
def load_stuff hos
|
30
25
|
case hos
|
31
26
|
when NilClass then Hashie::Mash.new # aka skip
|
@@ -45,7 +40,6 @@ module Kungfuig
|
|
45
40
|
fail ArgumentError.new "#{__callee__} accepts either String or Hash as parameter."
|
46
41
|
end
|
47
42
|
end
|
48
|
-
# rubocop:enable Metrics/MethodLength
|
49
43
|
module_function :load_stuff
|
50
44
|
|
51
45
|
module InstanceMethods
|
@@ -113,14 +107,6 @@ module Kungfuig
|
|
113
107
|
options.deep_merge! Kungfuig.load_stuff hos
|
114
108
|
end
|
115
109
|
private :merge_hash_or_string!
|
116
|
-
|
117
|
-
def lookup_aspects meth
|
118
|
-
# ⇓⇓⇓ eigenclass ⇓⇓⇓ ancestors
|
119
|
-
[(class << self; self; end), *self.class.ancestors].inject(ASPECT_TEMPLATE.call) do |memo, c|
|
120
|
-
c.respond_to?(:aspects?) && c.aspects? ? c.aspects(meth.to_sym).merge(memo) { |_, c1, c2| c1 | c2 } : memo
|
121
|
-
end
|
122
|
-
end
|
123
|
-
private :lookup_aspects
|
124
110
|
end
|
125
111
|
|
126
112
|
def self.included base
|
@@ -145,41 +131,18 @@ module Kungfuig
|
|
145
131
|
instance_eval(&block)
|
146
132
|
end
|
147
133
|
|
148
|
-
# rubocop:disable Metrics/MethodLength
|
149
134
|
def aspect meth, after = true
|
150
135
|
fail ArgumentError.new "Aspect must have a codeblock" unless block_given?
|
151
136
|
fail NoMethodError.new "Aspect must be attached to existing method" unless instance_methods.include? meth.to_sym
|
152
137
|
|
153
|
-
|
154
|
-
|
155
|
-
unless instance_methods.include?(:"#{ASPECT_PREFIX}#{meth}")
|
156
|
-
class_eval <<-CODE
|
157
|
-
alias_method :'#{ASPECT_PREFIX}#{meth}', :'#{meth}'
|
158
|
-
def #{meth}(*args, &cb)
|
159
|
-
ps = lookup_aspects(:'#{meth}')
|
160
|
-
ps[:before].each do |p|
|
161
|
-
p.call(self, :'#{meth}', nil, *args) # FIXME: allow argument modification!!!
|
162
|
-
end
|
163
|
-
send(:'#{ASPECT_PREFIX}#{meth}', *args, &cb).tap do |result|
|
164
|
-
ps[:after].each do |p|
|
165
|
-
p.call(self, :'#{meth}', result, *args)
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
CODE
|
170
|
-
end
|
171
|
-
|
172
|
-
meth.to_sym
|
173
|
-
end
|
174
|
-
# rubocop:enable Metrics/MethodLength
|
175
|
-
|
176
|
-
def aspects?
|
177
|
-
@aspects.is_a?(Hash)
|
138
|
+
Kungfuig::Prepender.new(self, meth).public_send((after ? :after : :before), &Proc.new)
|
178
139
|
end
|
179
140
|
|
180
|
-
def aspects
|
181
|
-
|
182
|
-
|
141
|
+
def aspects
|
142
|
+
ancestors.select { |a| a.name.nil? && a.ancestors.include?(I★I) }
|
143
|
+
.flat_map { |m| m.instance_methods(false) }
|
144
|
+
.group_by { |e| e }
|
145
|
+
.map { |k, v| [k, v.count] }.to_h
|
183
146
|
end
|
184
147
|
alias_method :set, :option!
|
185
148
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kungfuig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kantox LTD
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -92,14 +92,14 @@ dependencies:
|
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
95
|
+
version: '3'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
102
|
+
version: '3'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: cucumber
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,14 +134,14 @@ dependencies:
|
|
134
134
|
requirements:
|
135
135
|
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
137
|
+
version: '2'
|
138
138
|
type: :development
|
139
139
|
prerelease: false
|
140
140
|
version_requirements: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
142
|
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version: '
|
144
|
+
version: '2'
|
145
145
|
description: Config with goodnesses.
|
146
146
|
email:
|
147
147
|
- aleksei.matiushkin@kantox.com
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- lib/kungfuig/aspector.rb
|
169
169
|
- lib/kungfuig/color.rb
|
170
170
|
- lib/kungfuig/jobber.rb
|
171
|
+
- lib/kungfuig/prepender.rb
|
171
172
|
- lib/kungfuig/version.rb
|
172
173
|
homepage: http://kantox.com
|
173
174
|
licenses:
|