Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/static_model/active_support.rb
Overview
Naive fallbacks for ActiveSupport String extensions. Uses ActiveSupport if its available, otherwise, use these so at least it doesnt require AS and its a little faster for the common case
Instance Method Summary collapse
- #camelize ⇒ Object
- #classify ⇒ Object
- #foreign_key ⇒ Object
- #pluralize ⇒ Object
- #singularize ⇒ Object
- #tableize ⇒ Object
- #underscore ⇒ Object
Instance Method Details
#camelize ⇒ Object
15 16 17 |
# File 'lib/static_model/active_support.rb', line 15 def camelize self.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } end |
#classify ⇒ Object
11 12 13 |
# File 'lib/static_model/active_support.rb', line 11 def classify self.gsub(/.*\./, '').singularize.camelize end |
#foreign_key ⇒ Object
7 8 9 |
# File 'lib/static_model/active_support.rb', line 7 def foreign_key self.gsub(/^.*::/, '').underscore + "_id" end |
#pluralize ⇒ Object
27 28 29 |
# File 'lib/static_model/active_support.rb', line 27 def pluralize self + "s" end |
#singularize ⇒ Object
19 20 21 |
# File 'lib/static_model/active_support.rb', line 19 def singularize self.gsub(/s$/, '') end |
#tableize ⇒ Object
23 24 25 |
# File 'lib/static_model/active_support.rb', line 23 def tableize self.underscore.pluralize end |
#underscore ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/static_model/active_support.rb', line 31 def underscore self.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |