Class: Kungfuig::Prepender
- Inherits:
-
Object
- Object
- Kungfuig::Prepender
- Defined in:
- lib/kungfuig/prepender.rb
Defined Under Namespace
Classes: MalformedTarget
Constant Summary collapse
- AGRESSIVE_ERRORS =
true
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
-
#λ ⇒ Object
readonly
Returns the value of attribute λ.
Class Method Summary collapse
Instance Method Summary collapse
- #before(λ = nil) ⇒ Object (also: #after, #on_hook, #on_error)
-
#initialize(*args, **params) ⇒ Prepender
constructor
Parameters might be: • 1 — method instance — string in form “Class#method” • 2 — class (String, Symbol or Class), method name (String, Symbol) — instance (Object), method name (String, Symbol).
Constructor Details
#initialize(*args, **params) ⇒ Prepender
Parameters might be: • 1
— method instance
— string in form "Class#method"
• 2
— class (String, Symbol or Class), method name (String, Symbol)
— instance (Object), method name (String, Symbol)
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/kungfuig/prepender.rb', line 47 def initialize *args, **params @λ = { before: nil, after: nil, on_hook: nil } @klazz, @method, @receiver = case args.size when 1 case args.first when Method then [(class << args.first.receiver ; self ; end), args.first.name, args.first.receiver] when UnboundMethod then [args.first.owner, args.first.name] when String k, m = args.first.split('#') [k, m && m.to_sym] end when 2 case args.first when Module, String then [args.first, args.last.to_sym] when Symbol then [args.first.to_s.split('_').map(&:capitalize).join, args.last.to_sym] else [(class << args.first ; self ; end), args.last.to_sym, args.first] end end @options = params after(Proc.new) if block_given? # assign the block to after by default raise MalformedTarget.new "Unable to lookup class", args unless @klazz raise MalformedTarget.new "Unable to lookup method", args unless @method postpone_hook end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
38 39 40 |
# File 'lib/kungfuig/prepender.rb', line 38 def method @method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
38 39 40 |
# File 'lib/kungfuig/prepender.rb', line 38 def @options end |
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
38 39 40 |
# File 'lib/kungfuig/prepender.rb', line 38 def receiver @receiver end |
#λ ⇒ Object (readonly)
Returns the value of attribute λ.
38 39 40 |
# File 'lib/kungfuig/prepender.rb', line 38 def λ @λ end |
Class Method Details
.anteponer(*args) ⇒ Object
32 33 34 35 |
# File 'lib/kungfuig/prepender.rb', line 32 def anteponer *args raise MalformedTarget.new "Factory requires a block; use Prepender#new for more accurate tuning", args unless block_given? Prepender.new(*args, &Proc.new) end |
.error!(e, **hash) ⇒ Object
28 29 30 |
# File 'lib/kungfuig/prepender.rb', line 28 def error! e, **hash errors << [e, hash] end |
.errors ⇒ Object
24 25 26 |
# File 'lib/kungfuig/prepender.rb', line 24 def errors @errors ||= [] end |
Instance Method Details
#before(λ = nil) ⇒ Object Also known as: after, on_hook, on_error
76 77 78 79 |
# File 'lib/kungfuig/prepender.rb', line 76 def before λ = nil @λ[__callee__] = λ || (block_given? ? Proc.new : nil) self end |