Module: Phlex::Kit
- Defined in:
- lib/phlex/kit.rb
Defined Under Namespace
Modules: LazyLoader
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/phlex/kit.rb', line 35
def method_missing(name, ...)
if name[0] == name[0].upcase && constants.include?(name) && const_get(name) && methods.include?(name)
public_send(name, ...)
else
super
end
end
|
Class Method Details
.extended(mod) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/phlex/kit.rb', line 22
def self.extended(mod)
case mod
when Class
raise Phlex::ArgumentError.new(<<~MESSAGE)
`Phlex::Kit` was extended into #{mod.name}.
You should only extend modules with `Phlex::Kit` as it is not compatible with classes.
MESSAGE
else
mod.include(LazyLoader)
end
end
|
Instance Method Details
#const_added(name) ⇒ Object
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
75
76
77
78
79
80
81
82
|
# File 'lib/phlex/kit.rb', line 47
def const_added(name)
return if autoload?(name)
me = self
constant = const_get(name)
case constant
when Class
if constant < Phlex::SGML
constant.include(me)
constant = nil
define_method(name) do |*args, **kwargs, &block|
constant = me.const_get(name)
render(constant.new(*args, **kwargs), &block)
end
define_singleton_method(name) do |*args, **kwargs, &block|
component, fiber_id = Thread.current[:__phlex_component__]
if (component && fiber_id == Fiber.current.object_id)
component.instance_exec do
constant = me.const_get(name)
render(constant.new(*args, **kwargs), &block)
end
else
raise "You can't call `#{name}' outside of a Phlex rendering context."
end
end
end
when Module
constant.extend(Phlex::Kit)
end
super
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
43
44
45
|
# File 'lib/phlex/kit.rb', line 43
def respond_to_missing?(name, include_private = false)
(name[0] == name[0].upcase && constants.include?(name) && const_get(name) && methods.include?(name)) || super
end
|