attribute_localizer 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/attribute_localizer.rb +8 -4
  2. metadata +3 -3
@@ -7,17 +7,21 @@ module AttributeLocalizer
7
7
  module ClassMethods
8
8
 
9
9
  def localize_attributes(*attributes)
10
+ options = attributes.extract_options!
10
11
 
11
12
  klass = class << self; self end
12
13
 
13
14
  class_eval 'after_save :serialize_localizations'
14
- class_eval 'attr_accessor :locale'
15
+ class_eval 'attr_accessor :locale' if options[:locale_virtual]
15
16
  attributes.each { |attribute| class_eval "attr_accessor :#{attribute}" }
16
17
 
17
18
  src = attributes.map do |attribute|
18
19
  str = "def #{attribute}\n"
19
- str << "@#{attribute} || I18n.t(\"\#{self.class.send :localization_namespace}.\#{localization_hash_key}.#{attribute}\", :locale => locale)\n"
20
- str << "end"
20
+ str << " return @#{attribute} if @#{attribute}\n"
21
+ str << " @#{attribute} = I18n.t(\"\#{self.class.send :localization_namespace}.\#{localization_hash_key}.#{attribute}\", :locale => locale, :default => '')\n"
22
+ str << " @#{attribute} = nil unless @#{attribute}.present?\n"
23
+ str << " @#{attribute}\n"
24
+ str << "end\n"
21
25
  str
22
26
  end.join("\n")
23
27
 
@@ -26,7 +30,7 @@ module AttributeLocalizer
26
30
  src = <<-end_src
27
31
 
28
32
  def locale
29
- @locale || I18n.locale
33
+ #{options[:locale_virtual] ? '@locale' : 'super'} || I18n.locale
30
34
  end
31
35
 
32
36
  end_src
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 3
9
- version: 0.0.3
8
+ - 4
9
+ version: 0.0.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michael Deering
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-22 00:00:00 -06:00
17
+ date: 2010-04-28 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies: []
20
20