Class: I18nScopes::TranslationHelper
- Inherits:
-
Object
- Object
- I18nScopes::TranslationHelper
- Defined in:
- lib/i18n_scopes/translation_helper.rb
Overview
this class provides helper methods to determine the actual scope in your class
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path, options = {}) ⇒ TranslationHelper
constructor
Params: *
path
: the path from i18n_scope *options
the options from i18n_scope. -
#scope_from_path(object, options, parameter_matchings) ⇒ Object
Params: *
object
: the object which is doing a translation *options
: additional options for this translation *parameter_matchings
: a Hash providing arguments to custom methods.
Constructor Details
#initialize(path, options = {}) ⇒ TranslationHelper
Params:
-
path
: the path from i18n_scope -
options
the options from i18n_scope
12 13 14 15 |
# File 'lib/i18n_scopes/translation_helper.rb', line 12 def initialize(path, = {}) self.path = path self. = I18nScopes.configuration..merge() end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/i18n_scopes/translation_helper.rb', line 7 def @options end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/i18n_scopes/translation_helper.rb', line 6 def path @path end |
Instance Method Details
#scope_from_path(object, options, parameter_matchings) ⇒ Object
Params:
-
object
: the object which is doing a translation -
options
: additional options for this translation -
parameter_matchings
: a Hash providing arguments to custom methods
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/i18n_scopes/translation_helper.rb', line 21 def scope_from_path(object, , parameter_matchings) scope = [] custom_path = if .include?(:path) [*.delete(:path)] else self.path end custom_path += [*.delete(:path_extension)] if .include?(:path_extension) respondables = [object] respondables += [*.delete(:respondable)] if .include?(:respondable) respondables << I18nScopes::TranslationUtils # add utils at last parameter_matchings[:options] = self..merge(parameter_matchings[:options]) # merge options custom_path.each do |path_name| if path_name.is_a?(Symbol) # find a respondable which responds_to path_name respondable = respondables.find{ |respondable| respondable.respond_to?(path_name) } if respondable # call the path_name method on the respondable result = value_from_method_call(respondable, respondables, path_name, parameter_matchings) if result.is_a?(Array) # add all entries of an array scope += result else scope << result end else # no object is respondable for this path_name, so just add the symbol to the scope scope << path_name end elsif path_name.is_a?(String) scope << path_name end end return scope end |