Module: LocalizedKeys::InstanceMethods

Defined in:
lib/blue_pages/localized_keys.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/blue_pages/localized_keys.rb', line 71

def method_missing(name, *args)
  if self.respond_to_dynamic?(name)
    name.to_s =~ /(.*)_([a-z]{2})(=)??$/
    key, locale, assignment = $1, $2, $3
    localized_key = :"#{key}_locales"

    if assignment.nil?
      value = send(localized_key)
      value[locale] if value
    elsif
      value = send(localized_key)
      send(:"#{localized_key}=", {}) unless value
      send(localized_key)[locale] = args.first
    end
  else
    super
  end
end

Instance Method Details

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/blue_pages/localized_keys.rb', line 90

def respond_to?(*args)
  super || self.respond_to_dynamic?(args.first)
end