Class: ActiveSupport::SafeBuffer
- Inherits:
-
String
show all
- Defined in:
- activesupport/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", "prepend"].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, #inquiry, #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.
94
95
96
97
|
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 94
def initialize(*)
@dirty = false
super
end
|
Instance Method Details
113
114
115
|
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 113
def +(other)
dup.concat(other)
end
|
#concat(value) ⇒ Object
Also known as:
<<
104
105
106
107
108
109
110
|
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 104
def concat(value)
if dirty? || value.html_safe?
super(value)
else
super(ERB::Util.h(value))
end
end
|
#encode_with(coder) ⇒ Object
129
130
131
|
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 129
def encode_with(coder)
coder.represent_scalar nil, to_str
end
|
#html_safe? ⇒ Boolean
117
118
119
|
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 117
def html_safe?
!dirty?
end
|
#initialize_copy(other) ⇒ Object
99
100
101
102
|
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 99
def initialize_copy(other)
super
@dirty = other.dirty?
end
|
#safe_concat(value) ⇒ Object
89
90
91
92
|
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 89
def safe_concat(value)
raise SafeConcatError if dirty?
original_concat(value)
end
|
125
126
127
|
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 125
def to_param
to_str
end
|
121
122
123
|
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 121
def to_s
self
end
|
#to_yaml(*args) ⇒ Object
133
134
135
136
|
# File 'activesupport/lib/active_support/core_ext/string/output_safety.rb', line 133
def to_yaml(*args)
return super() if defined?(YAML::ENGINE) && !YAML::ENGINE.syck?
to_str.to_yaml(*args)
end
|