|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | # @api private
|
4 |
| -class Phlex::Rails::Unbuffered < BasicObject |
5 |
| - def initialize(object) |
6 |
| - @object = object |
| 4 | +class Phlex::Rails::Unbuffered |
| 5 | + def initialize(component) |
| 6 | + @component = component |
7 | 7 | end
|
8 | 8 |
|
9 |
| - def inspect |
10 |
| - "Unbuffered(#{@object.class.name})[object: #{@object.inspect}]" |
11 |
| - end |
12 |
| - |
13 |
| - define_method :__class__, |
14 |
| - ::Object.instance_method(:class) |
15 |
| - |
16 | 9 | def respond_to_missing?(...)
|
17 |
| - @object.respond_to?(...) |
| 10 | + @component.respond_to?(...) |
18 | 11 | end
|
19 | 12 |
|
20 |
| - def method_missing(name, ...) |
21 |
| - if @object.respond_to?(name) |
22 |
| - __class__.define_method(name) do |*a, **k, &b| |
23 |
| - @object.capture do |
24 |
| - if b |
25 |
| - @object.public_send(name, *a, **k) do |*aa| |
26 |
| - if aa.length == 1 && ::Phlex::SGML === aa[0] |
27 |
| - @object.helpers.capture( |
28 |
| - ::Phlex::Rails::Unbuffered.new(aa[0]), |
29 |
| - &b |
30 |
| - ) |
31 |
| - else |
32 |
| - @object.helpers.capture(*aa, &b) |
33 |
| - end |
34 |
| - end |
35 |
| - else |
36 |
| - @object.public_send(name, *a, **k) |
| 13 | + def method_missing(method_name, *, &erb) |
| 14 | + if @component.respond_to?(method_name) |
| 15 | + output = @component.capture do |
| 16 | + if erb |
| 17 | + @component.public_send(method_name, *) do |
| 18 | + @component.raw( |
| 19 | + @component.helpers.capture( |
| 20 | + &erb |
| 21 | + ), |
| 22 | + ) |
37 | 23 | end
|
| 24 | + else # no erb block |
| 25 | + @component.public_send( |
| 26 | + method_name, |
| 27 | + *, |
| 28 | + ) |
38 | 29 | end
|
39 | 30 | end
|
40 |
| - |
41 |
| - __send__(name, ...) |
42 | 31 | else
|
43 | 32 | super
|
44 | 33 | end
|
45 | 34 | end
|
46 | 35 |
|
47 |
| - # Forward some methods to the original underlying object |
| 36 | + def inspect |
| 37 | + "Unbuffered(#{@component.inspect})" |
| 38 | + end |
| 39 | + |
48 | 40 | def call(...)
|
49 |
| - @object.call(...) |
| 41 | + @component.call(...) |
50 | 42 | end
|
51 | 43 |
|
52 | 44 | def send(...)
|
53 |
| - @object.__send__(...) |
| 45 | + @component.__send__(...) |
54 | 46 | end
|
55 | 47 |
|
56 | 48 | def public_send(...)
|
57 |
| - @object.public_send(...) |
| 49 | + @component.public_send(...) |
58 | 50 | end
|
59 | 51 | end
|
0 commit comments