lib/alephant/renderer/views.rb in alephant-renderer-3.0.0 vs lib/alephant/renderer/views.rb in alephant-renderer-3.1.0
- old
+ new
@@ -1,23 +1,29 @@
module Alephant
module Renderer
module Views
- @@views = {}
+ class << self
+ def register(klass)
+ views[underscorify(klass.name.split('::').last)] = klass
+ end
- def self.register(klass)
- @@views[underscorify(klass.name.split("::").last)] = klass
- end
+ def get_registered_class(id)
+ views[id.downcase]
+ end
- def self.get_registered_class(id)
- @@views[id.downcase]
- end
+ def underscorify(str)
+ str.gsub(/::/, '/')
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\\1_\\2')
+ .gsub(/([a-z\d])([A-Z])/, '\\1_\\2')
+ .tr('-', '_')
+ .downcase
+ end
- def self.underscorify(str)
- str.gsub(/::/, "/").
- gsub(/([A-Z]+)([A-Z][a-z])/,"\\1_\\2").
- gsub(/([a-z\d])([A-Z])/,"\\1_\\2").
- tr("-", "_").
- downcase
+ private
+
+ def views
+ @views ||= {}
+ end
end
end
end
end