Module: AsyncPartial::ArrayBuffer

Defined in:
lib/async_partial.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#buffer_valuesObject

Returns the value of attribute buffer_values.



62
63
64
# File 'lib/async_partial.rb', line 62

def buffer_values
  @buffer_values
end

Instance Method Details

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



69
70
71
72
# File 'lib/async_partial.rb', line 69

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

#initializeObject



64
65
66
67
# File 'lib/async_partial.rb', line 64

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

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

Raises:

  • (ActiveSupport::SafeBuffer::SafeConcatError)


75
76
77
78
79
# File 'lib/async_partial.rb', line 75

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

#safe_expr_append=(val) ⇒ Object



82
83
84
85
# File 'lib/async_partial.rb', line 82

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

#to_sObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/async_partial.rb', line 87

def to_s
  result = @buffer_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