Module: RKit::Decoration::Base
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/r_kit/decoration/base.rb', line 58
def method_missing method_name, *args, &block
closure = super
if RKit::Decoration.config.recursive_decoration && closure.need_decoration?
closure.decorate(view_context: view)
else
closure
end
end
|
Class Method Details
.included(base) ⇒ Object
3
4
5
6
7
8
9
10
|
# File 'lib/r_kit/decoration/base.rb', line 3
def self.included base
base.singleton_attr_reader :decorated_class
base.singleton_attr_reader :after_initialize_procs, default: proc{ [] }
base.define_singleton_method :after_initialize, ->(&block) do
after_initialize_procs << block
end
end
|
Instance Method Details
#after_initialize! ⇒ Object
20
21
22
23
24
25
|
# File 'lib/r_kit/decoration/base.rb', line 20
def after_initialize!
decorated = self
__getobj__.define_singleton_method(:decorated){ decorated }
decorator_class.after_initialize_procs.each{ |after_initialize_proc| self.instance_eval &after_initialize_proc }
end
|
#decorate(*args) ⇒ Object
32
33
34
|
# File 'lib/r_kit/decoration/base.rb', line 32
def decorate *args
self
end
|
#decorated? ⇒ Boolean
36
|
# File 'lib/r_kit/decoration/base.rb', line 36
def decorated?() true end
|
#initialize(object, view_context: nil) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/r_kit/decoration/base.rb', line 13
def initialize object, view_context: nil
@view_context = view_context
super(object)
after_initialize!
end
|
#need_decoration? ⇒ Boolean
38
|
# File 'lib/r_kit/decoration/base.rb', line 38
def need_decoration?() false end
|
40
41
42
|
# File 'lib/r_kit/decoration/base.rb', line 40
def raw
__getobj__
end
|
49
50
51
52
53
54
55
|
# File 'lib/r_kit/decoration/base.rb', line 49
def view
(@@mutex ||= Mutex.new).synchronize do
@view_context ||= view_context
end
rescue ThreadError
nil
end
|