Module: I18nScopes::TranslationUtils
- Defined in:
- lib/i18n_scopes/translation_utils.rb
Class Method Summary collapse
-
.class_name(klass, options = {}) ⇒ Object
this method will return a underscored class_name.
-
.method_name ⇒ Object
returns the method name of the original caller.
-
.modules(klass) ⇒ Object
this method will return all modules in a array, each module will be underscored.
Class Method Details
.class_name(klass, options = {}) ⇒ Object
this method will return a underscored class_name
Note: plural_classes and strip_controller_suffix will be used here
Params:
-
klass
: the class on which the name should be get -
options
: options like plural_classes and strip_controller_suffix
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/i18n_scopes/translation_utils.rb', line 22 def self.class_name(klass, = {}) class_name = if [:strip_controller_suffix] && klass.respond_to?(:controller_name) klass.controller_name else demodulized = ActiveSupport::Inflector.demodulize(klass.name) ActiveSupport::Inflector.underscore(demodulized) end if [:plural_classes] ActiveSupport::Inflector.pluralize(class_name) else ActiveSupport::Inflector.singularize(class_name) end end |
.method_name ⇒ Object
returns the method name of the original caller
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/i18n_scopes/translation_utils.rb', line 37 def self.method_name found_scoped_t_at = nil caller.each_with_index do |call, index| if call.include?("scoped_translation") found_scoped_t_at = index break end end if found_scoped_t_at && call = caller[found_scoped_t_at + 1] if /^(.+?):(\d+)(?::in `(.*)')?/ =~ call return Regexp.last_match[3] end end raise "Failed to get method_name" end |
.modules(klass) ⇒ Object
this method will return all modules in a array, each module will be underscored
Params:
-
klass
: the klass of which the modules should be used
9 10 11 12 13 |
# File 'lib/i18n_scopes/translation_utils.rb', line 9 def self.modules(klass) modules = ActiveSupport::Inflector.deconstantize(klass.name) modules = ActiveSupport::Inflector.underscore(modules) modules.split("::") end |