Class: InlineTemplates::BufferWrapper
Constant Summary
collapse
- IMPLICIT_CAST_METHODS =
::Set.new([ :to_int, :to_ary, :to_str, :to_sym, :to_hash, :to_proc, :to_io ])
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BlankObject
drop_methods, make_blank
Constructor Details
#initialize(object, buffer) ⇒ BufferWrapper
Returns a new instance of BufferWrapper.
7
8
9
10
|
# File 'lib/inline_templates/buffer_wrapper.rb', line 7
def initialize(object, buffer)
@object = object
@buffer = buffer
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/inline_templates/buffer_wrapper.rb', line 19
def method_missing(name, *args, &block)
args.map! &BufferWrapper.method(:unwrap)
block = BufferWrapper.create_proxy_proc(block, @buffer) unless block.nil?
result = @object.__send__(name, *args, &block)
return result if IMPLICIT_CAST_METHODS.include?(name.to_sym)
BufferWrapper.wrap result, @buffer
end
|
Class Method Details
.create_proxy_proc(nested, buffer) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/inline_templates/buffer_wrapper.rb', line 50
def self.create_proxy_proc(nested, buffer)
original_self = self
proc do |*args, &block|
args.map! { |arg| BufferWrapper.wrap arg, buffer }
block = BufferWrapper.create_proxy_proc(block, buffer) unless block.nil?
if self.equal? original_self
nested.call *args, &block
else
buffer.inlinetemplates_instance_exec self, *args, &nested
end
end
end
|
.unwrap(obj) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/inline_templates/buffer_wrapper.rb', line 42
def self.unwrap(obj)
if obj.respond_to? :__inline_templates_object
obj.__inline_templates_object
else
obj
end
end
|
.wrap(result, buffer) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/inline_templates/buffer_wrapper.rb', line 34
def self.wrap(result, buffer)
if result.class == ::NilClass || result.class == ::TrueClass || result.class == ::FalseClass
result
else
BufferWrapper.new(self.unwrap(result), buffer)
end
end
|
Instance Method Details
#__inline_templates_object ⇒ Object
12
|
# File 'lib/inline_templates/buffer_wrapper.rb', line 12
def __inline_templates_object; @object; end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
30
31
32
|
# File 'lib/inline_templates/buffer_wrapper.rb', line 30
def respond_to_missing?(name, include_private = false)
@object.respond_to?(name, include_private)
end
|
#~ ⇒ Object
14
15
16
17
|
# File 'lib/inline_templates/buffer_wrapper.rb', line 14
def ~
@buffer.inlinetemplates_append @object
@object
end
|