Class: ActiveSupport::SafeBuffer
- Inherits:
-
String
show all
- Defined in:
- lib/active_support/core_ext/string/output_safety.rb
Defined Under Namespace
Classes: SafeConcatError
Constant Summary
collapse
- UNSAFE_STRING_METHODS =
["capitalize", "chomp", "chop", "delete", "downcase", "gsub", "lstrip", "next", "reverse", "rstrip", "slice", "squeeze", "strip", "sub", "succ", "swapcase", "tr", "tr_s", "upcase"].freeze
Instance Method Summary
collapse
Methods inherited from String
#acts_like_string?, #as_json, #at, #blank?, #camelize, #classify, #constantize, #dasherize, #demodulize, #encode_json, #encoding_aware?, #exclude?, #first, #foreign_key, #from, #html_safe, #humanize, #is_utf8?, #last, #mb_chars, #ord, #parameterize, #pluralize, #singularize, #squish, #squish!, #strip_heredoc, #tableize, #titleize, #to, #to_date, #to_datetime, #to_time, #truncate, #underscore
Constructor Details
Returns a new instance of SafeBuffer.
93
94
95
96
|
# File 'lib/active_support/core_ext/string/output_safety.rb', line 93
def initialize(*)
@dirty = false
super
end
|
Instance Method Details
112
113
114
|
# File 'lib/active_support/core_ext/string/output_safety.rb', line 112
def +(other)
dup.concat(other)
end
|
#concat(value) ⇒ Object
Also known as:
<<
103
104
105
106
107
108
109
|
# File 'lib/active_support/core_ext/string/output_safety.rb', line 103
def concat(value)
if dirty? || value.html_safe?
super(value)
else
super(ERB::Util.h(value))
end
end
|
#html_safe? ⇒ Boolean
116
117
118
|
# File 'lib/active_support/core_ext/string/output_safety.rb', line 116
def html_safe?
!dirty?
end
|
#initialize_copy(other) ⇒ Object
98
99
100
101
|
# File 'lib/active_support/core_ext/string/output_safety.rb', line 98
def initialize_copy(other)
super
@dirty = other.dirty?
end
|
#safe_concat(value) ⇒ Object
88
89
90
91
|
# File 'lib/active_support/core_ext/string/output_safety.rb', line 88
def safe_concat(value)
raise SafeConcatError if dirty?
original_concat(value)
end
|
124
125
126
|
# File 'lib/active_support/core_ext/string/output_safety.rb', line 124
def to_param
to_str
end
|
120
121
122
|
# File 'lib/active_support/core_ext/string/output_safety.rb', line 120
def to_s
self
end
|
#to_yaml(*args) ⇒ Object
128
129
130
|
# File 'lib/active_support/core_ext/string/output_safety.rb', line 128
def to_yaml(*args)
to_str.to_yaml(*args)
end
|