Refactoring: Improving performance by memorizing app_model string generation.
This commit is contained in:
parent
197ecade07
commit
b361b43836
1 changed files with 8 additions and 8 deletions
|
@ -1,15 +1,15 @@
|
|||
class Class
|
||||
def to_app_model_url
|
||||
camel_cased_word = to_s
|
||||
camel_cased_word.gsub(/::/, '_')
|
||||
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
||||
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
||||
.tr('-', '_')
|
||||
.downcase
|
||||
@to_app_model_url ||= begin
|
||||
to_s.gsub(/::/, '_')
|
||||
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
||||
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
||||
.tr('-', '_')
|
||||
.downcase
|
||||
end
|
||||
end
|
||||
|
||||
def to_app_model
|
||||
camel_cased_word = to_s
|
||||
camel_cased_word.gsub(/::/, '').to_sym
|
||||
@to_app_model ||= to_s.gsub(/::/, '').to_sym
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue