Module: Wallaby::Inflector
Overview
Convert strings
Instance Method Summary collapse
-
#to_authorizer_name(script_name, resources_name) ⇒ String
Authorizer name.
- #to_class_name(name) ⇒ String?
-
#to_controller_name(script_name, resources_name) ⇒ String
Controller name.
-
#to_decorator_name(script_name, resources_name) ⇒ String
Decorator name.
-
#to_model_label(model_class) ⇒ String
Produce model label (e.g. ‘Namespace / Product`) for model class (e.g. `Namespace::Product`).
-
#to_model_name(name) ⇒ String
Resource name.
-
#to_paginator_name(script_name, resources_name) ⇒ String
Paginator name.
-
#to_resource_name(name) ⇒ String
Resource name.
-
#to_resources_name(name) ⇒ String
Resources name.
-
#to_script(script_name, resources_name, suffix = nil) ⇒ String
Generate the prefix for all classes.
-
#to_servicer_name(script_name, resources_name) ⇒ String
Servicer name.
Instance Method Details
#to_authorizer_name(script_name, resources_name) ⇒ String
Returns authorizer name.
44 45 46 |
# File 'lib/utils/wallaby/inflector.rb', line 44 def (script_name, resources_name) to_class_name(to_script(script_name, to_resource_name(resources_name), AUTHORIZER)) end |
#to_class_name(name) ⇒ String?
11 12 13 14 15 16 |
# File 'lib/utils/wallaby/inflector.rb', line 11 def to_class_name(name) return EMPTY_STRING if name.blank? name = name.to_s unless name.is_a?(String) name.gsub(COLONS, SLASH).classify end |
#to_controller_name(script_name, resources_name) ⇒ String
Returns controller name.
30 31 32 |
# File 'lib/utils/wallaby/inflector.rb', line 30 def to_controller_name(script_name, resources_name) to_class_name(to_script(script_name, to_resources_name(resources_name), CONTROLLER)) end |
#to_decorator_name(script_name, resources_name) ⇒ String
Returns decorator name.
37 38 39 |
# File 'lib/utils/wallaby/inflector.rb', line 37 def to_decorator_name(script_name, resources_name) to_class_name(to_script(script_name, to_resource_name(resources_name), DECORATOR)) end |
#to_model_label(model_class) ⇒ String
Produce model label (e.g. ‘Namespace / Product`) for model class (e.g. `Namespace::Product`)
86 87 88 89 90 91 92 |
# File 'lib/utils/wallaby/inflector.rb', line 86 def to_model_label(model_class) # TODO: change to use i18n translation return EMPTY_STRING if model_class.blank? model_class_name = to_model_name model_class model_class_name.titleize.gsub(SLASH, SPACE + SLASH + SPACE) end |
#to_model_name(name) ⇒ String
Returns resource name.
79 80 81 |
# File 'lib/utils/wallaby/inflector.rb', line 79 def to_model_name(name) to_class_name(to_resource_name(name)) end |
#to_paginator_name(script_name, resources_name) ⇒ String
Returns paginator name.
58 59 60 |
# File 'lib/utils/wallaby/inflector.rb', line 58 def to_paginator_name(script_name, resources_name) to_class_name(to_script(script_name, to_resource_name(resources_name), PAGINATOR)) end |
#to_resource_name(name) ⇒ String
Returns resource name.
73 74 75 |
# File 'lib/utils/wallaby/inflector.rb', line 73 def to_resource_name(name) to_resources_name(name).singularize end |
#to_resources_name(name) ⇒ String
Returns resources name.
64 65 66 67 68 69 |
# File 'lib/utils/wallaby/inflector.rb', line 64 def to_resources_name(name) return EMPTY_STRING if name.blank? name = name.to_s unless name.is_a?(String) name.tableize end |
#to_script(script_name, resources_name, suffix = nil) ⇒ String
Returns generate the prefix for all classes.
22 23 24 25 |
# File 'lib/utils/wallaby/inflector.rb', line 22 def to_script(script_name, resources_name, suffix = nil) normalized_suffix = suffix.try(:underscore).try(:gsub, /\A_?/, UNDERSCORE) "#{script_name}/#{resources_name}#{normalized_suffix}".gsub(%r{\A/+}, EMPTY_STRING) end |
#to_servicer_name(script_name, resources_name) ⇒ String
Returns servicer name.
51 52 53 |
# File 'lib/utils/wallaby/inflector.rb', line 51 def to_servicer_name(script_name, resources_name) to_class_name(to_script(script_name, to_resource_name(resources_name), SERVICER)) end |