Module: ROM::Inflector
- Defined in:
- lib/rom/support/inflector.rb
Overview
Helper module providing thin interface around an inflection backend.
Constant Summary collapse
- BACKENDS =
{ activesupport: [ 'active_support/inflector', proc { ::ActiveSupport::Inflector } ], inflecto: [ 'inflecto', proc { ::Inflecto } ] }.freeze
Class Method Summary collapse
- .camelize(input) ⇒ Object
- .classify(input) ⇒ Object
- .constantize(input) ⇒ Object
- .demodulize(input) ⇒ Object
- .detect_backend ⇒ Object
- .inflector ⇒ Object
- .pluralize(input) ⇒ Object
- .realize_backend(path, inflector_backend_factory) ⇒ Object
- .select_backend(name = nil) ⇒ Object
- .singularize(input) ⇒ Object
- .underscore(input) ⇒ Object
Class Method Details
.camelize(input) ⇒ Object
45 46 47 |
# File 'lib/rom/support/inflector.rb', line 45 def self.camelize(input) inflector.camelize(input) end |
.classify(input) ⇒ Object
69 70 71 |
# File 'lib/rom/support/inflector.rb', line 69 def self.classify(input) inflector.classify(input) end |
.constantize(input) ⇒ Object
65 66 67 |
# File 'lib/rom/support/inflector.rb', line 65 def self.constantize(input) inflector.constantize(input) end |
.demodulize(input) ⇒ Object
61 62 63 |
# File 'lib/rom/support/inflector.rb', line 61 def self.demodulize(input) inflector.demodulize(input) end |
.detect_backend ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/rom/support/inflector.rb', line 24 def self.detect_backend BACKENDS.find do |_, (path, inflector_class)| backend = realize_backend(path, inflector_class) break backend if backend end || raise(LoadError, "No inflector library could be found: "\ "please install either the `inflecto` or `activesupport` gem.") end |
.inflector ⇒ Object
41 42 43 |
# File 'lib/rom/support/inflector.rb', line 41 def self.inflector defined?(@inflector) && @inflector || select_backend end |
.pluralize(input) ⇒ Object
57 58 59 |
# File 'lib/rom/support/inflector.rb', line 57 def self.pluralize(input) inflector.pluralize(input) end |
.realize_backend(path, inflector_backend_factory) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/rom/support/inflector.rb', line 17 def self.realize_backend(path, inflector_backend_factory) require path inflector_backend_factory.call rescue LoadError nil end |
.select_backend(name = nil) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/rom/support/inflector.rb', line 34 def self.select_backend(name = nil) if name && !BACKENDS.key?(name) raise NameError, "Invalid inflector library selection: '#{name}'" end @inflector = name ? realize_backend(*BACKENDS[name]) : detect_backend end |
.singularize(input) ⇒ Object
53 54 55 |
# File 'lib/rom/support/inflector.rb', line 53 def self.singularize(input) inflector.singularize(input) end |
.underscore(input) ⇒ Object
49 50 51 |
# File 'lib/rom/support/inflector.rb', line 49 def self.underscore(input) inflector.underscore(input) end |