Module: AsyncPartial::ArrayBuffer

Defined in:
lib/async_partial.rb

Instance Method Summary collapse

Instance Method Details

#<<(value) ⇒ Object Also known as: append=



46
47
48
49
# File 'lib/async_partial.rb', line 46

def <<(value)
  @values << [value, :<<] unless value.nil?
  self
end

#initializeObject



41
42
43
44
# File 'lib/async_partial.rb', line 41

def initialize(*)
  super
  @values = []
end

#safe_concat(value) ⇒ Object Also known as: safe_append=

Raises:

  • (ActiveSupport::SafeBuffer::SafeConcatError)


52
53
54
55
56
# File 'lib/async_partial.rb', line 52

def safe_concat(value)
  raise ActiveSupport::SafeBuffer::SafeConcatError unless html_safe?
  @values << [value, :safe_concat] unless value.nil?
  self
end

#safe_expr_append=(val) ⇒ Object



59
60
61
62
# File 'lib/async_partial.rb', line 59

def safe_expr_append=(val)
  @values << [val, :safe_expr_append] unless val.nil?
  self
end

#to_sObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/async_partial.rb', line 64

def to_s
  result = @values.each_with_object(ActiveSupport::SafeBuffer.new) do |(v, meth), buf|
    if meth == :<<
      if AsyncPartial::AsyncResult === v
        buf << v.value
      else
        buf << v.to_s
      end
    else
      if AsyncPartial::AsyncResult === v
        buf.safe_concat(v.value)
      else
        buf.safe_concat(v.to_s)
      end
    end
  end
  result.to_s
end