ragot 0.1.0 → 0.2.0
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/lib/ragot.rb +17 -11
- data/lib/ragot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99aa743259857da300cabe7e3598eeee6fda7a93
|
4
|
+
data.tar.gz: 324dba4e829981e7de9b213a283778165c9268dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 195ebf5a2d7ed91abce895340bf795061905cdf4e74ae4293356c388750cd3af9840fc83fb302464216832439db39eca5b657c62f39c07d3cdedac312b930249
|
7
|
+
data.tar.gz: 7eebfcfcdcfef56ffa1e5f0775fbc75f876a78658a97d25f31f93e14476fc2599e1d59333a77c5934f9c79b349a03ed4f4889c3f775c8fda42d2082b41506e20
|
data/lib/ragot.rb
CHANGED
@@ -82,24 +82,28 @@ module Ragot
|
|
82
82
|
def __incept_ragot(meth, blk, options)
|
83
83
|
o = { hook: :after, failsafe: FAILSAFE[Ragot.env], env: Ragot.env }.merge(options)
|
84
84
|
k = o[:class] ? @klass.singleton_class : @klass
|
85
|
-
|
85
|
+
f = (fp = o[:filter_params]) && o[:filter_params].is_a?(Proc) && o[:filter_params]
|
86
|
+
i ||= @i[k][meth] ||= { before: [], after: [], filter: nil, inherit: o[:inherit] }
|
86
87
|
|
87
88
|
return unless Array(o[:env]).map(&:to_s).include? Ragot.env
|
88
89
|
return unless (k.instance_methods + k.private_instance_methods).include? meth.to_sym
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
91
|
+
i[:alias] ||= redefine k, meth, @i[k][meth], self.class
|
92
|
+
i[:filter] = [ o[:failsafe], f || default_hook(i[:alias], nil, FILTER_HOOK) ] if fp
|
93
|
+
i[:before].unshift [ o[:failsafe], default_hook(meth, :before) ] if o[:stamp]
|
94
|
+
i[o[:hook]] << [ o[:failsafe], blk || default_hook(meth, o[:hook]) ]
|
93
95
|
end
|
94
96
|
|
95
|
-
def redefine(klass, meth, i)
|
96
|
-
klass.send :alias_method, "__ragot_inception_#{meth}", meth
|
97
|
+
def redefine(klass, meth, i, d)
|
98
|
+
klass.send :alias_method, orig = "__ragot_inception_#{meth}", meth
|
97
99
|
klass.send :define_method, meth, ->(*_, &b) {
|
98
|
-
|
99
|
-
|
100
|
-
i[:
|
100
|
+
own = i[:inherit] || self.class == klass || singleton_class == klass
|
101
|
+
own && (i[:before]).each { |exe| d.exec_hook self, *exe, *_ }
|
102
|
+
r = send i[:alias], *(i[:filter] && own ? d.exec_hook(self, *i[:filter], *_) : _), &b
|
103
|
+
own && i[:after].each { |exe| d.exec_hook self, *exe, r, *_ }
|
101
104
|
r
|
102
105
|
}
|
106
|
+
orig
|
103
107
|
end
|
104
108
|
|
105
109
|
MESSAGE = { before: "Entered %s, with params %s,%s at %s .%s",
|
@@ -112,8 +116,10 @@ module Ragot
|
|
112
116
|
ragot_talk MESSAGE[hook] % [meth, _.to_s, result, *time]
|
113
117
|
}
|
114
118
|
|
115
|
-
|
116
|
-
|
119
|
+
FILTER_HOOK = ->(h, meth, *_) { _.shift method(meth).parameters.size }
|
120
|
+
|
121
|
+
def default_hook(meth, hook, exe=DEFAULT_HOOK)
|
122
|
+
->(*_) { instance_exec hook, meth, _.shift, *_, &exe }
|
117
123
|
end
|
118
124
|
|
119
125
|
end
|
data/lib/ragot/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ragot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lacravate
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|