Class: NaranyaEcm::Rest::Model::LocalizedAttribute
- Inherits:
-
HashWithIndifferentAccess
- Object
- HashWithIndifferentAccess
- NaranyaEcm::Rest::Model::LocalizedAttribute
show all
- Defined in:
- lib/naranya_ecm/rest/model.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of LocalizedAttribute.
16
17
18
19
20
|
# File 'lib/naranya_ecm/rest/model.rb', line 16
def initialize(*args)
super()
given_attrs = args.shift
given_attrs.each { |k,v| self[k] = v } unless given_attrs.nil?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/naranya_ecm/rest/model.rb', line 33
def method_missing(method_name, *args, &block)
if method_name == self.class.aliased_lookup_name
self.class.send :alias_method, self.class.aliased_lookup_name, :lookup
lookup
else
super end
end
|
Class Method Details
.aliased_lookup_name ⇒ Object
48
49
50
|
# File 'lib/naranya_ecm/rest/model.rb', line 48
def aliased_lookup_name
@lookup_alias ||= self.name.demodulize[0..-("Translations".length+1)].underscore.to_sym
end
|
Instance Method Details
#lookup ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/naranya_ecm/rest/model.rb', line 22
def lookup
locale = ::I18n.locale
if ::I18n.respond_to?(:fallbacks)
lookup_result = self[::I18n.fallbacks[locale].map(&:to_s).find{ |loc| self.has_key?(loc) }]
else
lookup_result = self[locale.to_s]
end
lookup_result = self.present? ? self.first[1] : nil unless lookup_result.present?
lookup_result
end
|