has_translations 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- HasTranslations v0.3.3
1
+ HasTranslations v0.3.5
2
2
  ======================
3
3
 
4
4
  This simple plugin creates translations for your model.
5
5
  Uses delegation pattern: http://en.wikipedia.org/wiki/Delegation_pattern
6
6
 
7
- Tested with ActiveRecord versions: 2.3.5, 2.3.9, 3.0.0 (to test with Rails 3 run `rake RAILS_VERSION=3.0`)
7
+ Tested with ActiveRecord versions: 2.3.5, 2.3.9, 3.0.0, 3.1.0 (to test with Rails 3.1 run `rake RAILS_VERSION=3.1`)
8
8
  And tested with ruby 1.8.7 and 1.9.2
9
9
 
10
10
  Installation
@@ -19,6 +19,6 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.license = 'MIT'
22
- s.add_dependency "activesupport", "~> 2.3"
23
- s.add_dependency 'activerecord', '~> 2.3'
22
+ s.add_dependency 'activesupport', '> 2.3'
23
+ s.add_dependency 'activerecord', '> 2.3'
24
24
  end
@@ -78,27 +78,35 @@ class ActiveRecord::Base
78
78
  # <tt>all_translations</tt> method that returns all possible translations in
79
79
  # ordered hash (useful when creating forms with nested attributes).
80
80
  def self.translations(*attrs)
81
+ new_options = attrs.extract_options!
81
82
  options = {
82
83
  :fallback => false,
83
84
  :reader => true,
84
85
  :writer => false,
85
- :nil => ''
86
- }.merge(attrs.extract_options!)
86
+ :nil => '',
87
+ :autosave => new_options[:writer]
88
+ }.merge(new_options)
87
89
 
88
- options.assert_valid_keys([:fallback, :reader, :writer, :nil])
90
+ options.assert_valid_keys([:fallback, :reader, :writer, :nil, :autosave])
89
91
 
90
92
  translation_class_name = "#{self.model_name}Translation"
91
93
  translation_class = translation_class_name.constantize
92
94
  belongs_to = self.model_name.demodulize.underscore.to_sym
93
95
 
94
- write_inheritable_attribute :has_translations_options, options
95
- class_inheritable_reader :has_translations_options
96
+ if ActiveRecord::VERSION::MAJOR < 3
97
+ write_inheritable_attribute :has_translations_options, options
98
+ class_inheritable_reader :has_translations_options
96
99
 
97
- # Workaround to support Rails 2
98
- scope_method = if ActiveRecord::VERSION::MAJOR < 3 then :named_scope else :scope end
100
+ scope_method = :named_scope
101
+ else
102
+ class_attribute :has_translations_options
103
+ self.has_translations_options = options
104
+
105
+ scope_method = :scope
106
+ end
99
107
 
100
108
  # associations, validations and scope definitions
101
- has_many :translations, :class_name => translation_class_name, :dependent => :destroy, :autosave => true
109
+ has_many :translations, :class_name => translation_class_name, :dependent => :destroy, :autosave => options[:autosave]
102
110
  translation_class.belongs_to belongs_to
103
111
  translation_class.validates_presence_of :locale
104
112
  translation_class.validates_uniqueness_of :locale, :scope => :"#{belongs_to}_id"
@@ -1,3 +1,3 @@
1
1
  module HasTranslations
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
 
4
- rails_version = "~> #{ENV['RAILS_VERSION'] || '3.0.0'}"
4
+ rails_version = "~> #{ENV['RAILS_VERSION'] || '3.1.0'}"
5
5
 
6
6
  gem 'activerecord', rails_version
7
7
  gem 'activesupport', rails_version
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_translations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 4
10
- version: 0.3.4
9
+ - 5
10
+ version: 0.3.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dmitry Polushkin
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-09 00:00:00 Z
18
+ date: 2011-11-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activesupport
@@ -23,7 +23,7 @@ dependencies:
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  none: false
25
25
  requirements:
26
- - - ~>
26
+ - - ">"
27
27
  - !ruby/object:Gem::Version
28
28
  hash: 5
29
29
  segments:
@@ -38,7 +38,7 @@ dependencies:
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ~>
41
+ - - ">"
42
42
  - !ruby/object:Gem::Version
43
43
  hash: 5
44
44
  segments: