mirror of
https://github.com/heartcombo/simple_form.git
synced 2022-11-09 12:19:26 -05:00
cac943e891
I noticed these files all had strings such as "", " ", "_" that were allocated each time some common methods were called, over 1000x on a page in my app. This comment freezes all of these strings such that they're only allocated once, saving many KB of memory allocation.
23 lines
600 B
Ruby
23 lines
600 B
Ruby
# frozen_string_literal: true
|
|
module SimpleForm
|
|
module Components
|
|
# Needs to be enabled in order to do automatic lookups.
|
|
module Readonly
|
|
def readonly(wrapper_options = nil)
|
|
if readonly_attribute? && !has_readonly?
|
|
input_html_options[:readonly] ||= true
|
|
input_html_classes << :readonly
|
|
end
|
|
nil
|
|
end
|
|
|
|
private
|
|
|
|
def readonly_attribute?
|
|
object.class.respond_to?(:readonly_attributes) &&
|
|
object.persisted? &&
|
|
object.class.readonly_attributes.include?(attribute_name.to_s)
|
|
end
|
|
end
|
|
end
|
|
end
|