Module: Phlex::Kit
Defined Under Namespace
Modules: LazyLoader
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from LazyLoader
#method_missing, #respond_to_missing?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Phlex::Kit::LazyLoader
Class Method Details
.extended(mod) ⇒ Object
24
25
26
27
28
|
# File 'lib/phlex/kit.rb', line 24
def self.extended(mod)
mod.include(LazyLoader)
mod.define_method(:__phlex_kit_constants__) { mod.__phlex_kit_constants__ }
mod.define_method(:__get_phlex_kit_constant__) { |name| mod.__get_phlex_kit_constant__(name) }
end
|
Instance Method Details
#__get_phlex_kit_constant__(name) ⇒ Object
34
35
36
|
# File 'lib/phlex/kit.rb', line 34
def __get_phlex_kit_constant__(name)
const_get(name)
end
|
#__phlex_kit_constants__ ⇒ Object
30
31
32
|
# File 'lib/phlex/kit.rb', line 30
def __phlex_kit_constants__
constants
end
|
#const_added(name) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/phlex/kit.rb', line 38
def const_added(name)
return if autoload?(name)
constant = const_get(name)
if Class === constant && constant < Phlex::SGML
if instance_methods.include?(name)
raise NameError, "The instance method `#{name}' is already defined on `#{inspect}`."
elsif methods.include?(name)
raise NameError, "The method `#{name}' is already defined on `#{inspect}`."
end
constant.include(self)
define_method(name) do |*args, **kwargs, &block|
render(constant.new(*args, **kwargs), &block)
end
define_singleton_method(name) do |*args, **kwargs, &block|
if (component = Fiber[:__phlex_component__])
component.instance_exec do
render(constant.new(*args, **kwargs), &block)
end
else
raise "You can't call `#{name}' outside of a Phlex rendering context."
end
end
end
super
end
|