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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ragot.rb +17 -11
  3. data/lib/ragot/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c216474c3222f72271de2c6018be7b6b2332ca07
4
- data.tar.gz: 6a429decec07ff3889b96d80769a14a90c23c1e0
3
+ metadata.gz: 99aa743259857da300cabe7e3598eeee6fda7a93
4
+ data.tar.gz: 324dba4e829981e7de9b213a283778165c9268dd
5
5
  SHA512:
6
- metadata.gz: 7ce756577cd34a40b6be973a80323043c79be8cf57b7869d191385a59213bc63e1beb6ec3b0d670d074dfa2d14a0c6b1bb197c32430fbaa769ccd725c73c0d18
7
- data.tar.gz: 7bbe3ff6aeed846184820acf7ebca8c8da956b422224ea200189ea3caa981a05562e132629f5464cd3b0823999012936376cb887e05ff09bb09db0fd8bc28489
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
- @i[k][meth] ||= { before: [], after: [], stamp: [] }
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
- @i[k][meth][ :stamp ] << [ o[:failsafe], default_hook(meth, :before) ] if o[:stamp]
91
- @i[k][meth][o[:hook]] << [ o[:failsafe], blk || default_hook(meth, o[:hook]) ]
92
- @i[k][meth][:alias] ||= redefine k, meth, @i[k][meth]
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
- (i[:stamp] + i[:before]).each { |exe| Declaration.exec_hook self, *exe, *_ }
99
- r = send "__ragot_inception_#{meth}", *_, &b
100
- i[:after].each { |exe| Declaration.exec_hook self, *exe, r, *_ }
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
- def default_hook(meth, hook)
116
- ->(*_) { instance_exec hook, meth, _.shift, *_, &DEFAULT_HOOK }
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
@@ -1,3 +1,3 @@
1
1
  module Ragot
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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: 2016-09-28 00:00:00.000000000 Z
11
+ date: 2017-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry