has_translations 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
- HasTranslations v0.3.2
1
+ HasTranslations v0.3.3
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
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`)
8
+ And tested with ruby 1.8.7 and 1.9.2
8
9
 
9
10
  Installation
10
11
  ============
data/Rakefile CHANGED
@@ -31,7 +31,7 @@ begin
31
31
  gemspec.email = "dmitry.polushkin@gmail.com"
32
32
  gemspec.homepage = "http://github.com/dmitry/has_translations"
33
33
  gemspec.authors = ["Dmitry Polushkin"]
34
- gemspec.version = '0.3.2'
34
+ gemspec.version = '0.3.3'
35
35
  end
36
36
  rescue LoadError
37
37
  puts "Jeweler not available. Install it with: gem install jeweler"
data/TODO ADDED
@@ -0,0 +1,2 @@
1
+ http://github.com/technicalpickles/jeweler
2
+ http://wiki.github.com/qrush/gemcutter/create
@@ -5,15 +5,16 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{has_translations}
8
- s.version = "0.3.2"
8
+ s.version = "0.3.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dmitry Polushkin"]
12
- s.date = %q{2011-02-04}
12
+ s.date = %q{2011-02-21}
13
13
  s.description = %q{Create translations for your ActiveRecord models. Uses delegate pattern. Fully tested and used in a several production sites.}
14
14
  s.email = %q{dmitry.polushkin@gmail.com}
15
15
  s.extra_rdoc_files = [
16
- "README.md"
16
+ "README.md",
17
+ "TODO"
17
18
  ]
18
19
  s.files = [
19
20
  "MIT-LICENSE",
@@ -34,7 +35,7 @@ Gem::Specification.new do |s|
34
35
  ]
35
36
  s.homepage = %q{http://github.com/dmitry/has_translations}
36
37
  s.require_paths = ["lib"]
37
- s.rubygems_version = %q{1.5.0}
38
+ s.rubygems_version = %q{1.3.7}
38
39
  s.summary = %q{Create translations for your ActiveRecord models.}
39
40
  s.test_files = [
40
41
  "test/has_translations_test.rb",
@@ -43,6 +44,7 @@ Gem::Specification.new do |s|
43
44
  ]
44
45
 
45
46
  if s.respond_to? :specification_version then
47
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
48
  s.specification_version = 3
47
49
 
48
50
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -94,6 +94,18 @@ class ActiveRecord::Base
94
94
  write_inheritable_attribute :has_translations_options, options
95
95
  class_inheritable_reader :has_translations_options
96
96
 
97
+ # Workaround to support Rails 2
98
+ scope_method = if ActiveRecord::VERSION::MAJOR < 3 then :named_scope else :scope end
99
+
100
+ # associations, validations and scope definitions
101
+ has_many :translations, :class_name => translation_class_name, :dependent => :destroy
102
+ translation_class.belongs_to belongs_to
103
+ translation_class.validates_presence_of :locale
104
+ translation_class.validates_uniqueness_of :locale, :scope => :"#{belongs_to}_id"
105
+ send scope_method, :translated, lambda { |locale| {:conditions => ["#{translation_class.table_name}.locale = ?", locale.to_s], :joins => :translations} }
106
+
107
+ public
108
+
97
109
  def find_or_create_translation(locale)
98
110
  locale = locale.to_s
99
111
  (find_translation(locale) || self.translations.new).tap do |t|
@@ -142,17 +154,6 @@ class ActiveRecord::Base
142
154
  end
143
155
  end
144
156
 
145
- has_many :translations, :class_name => translation_class_name, :dependent => :destroy
146
-
147
- translation_class.belongs_to belongs_to
148
- translation_class.validates_presence_of :locale
149
- translation_class.validates_uniqueness_of :locale, :scope => :"#{belongs_to}_id"
150
-
151
- # Workaround to support Rails 2
152
- scope_method = if ActiveRecord::VERSION::MAJOR < 3 then :named_scope else :scope end
153
-
154
- send scope_method, :translated, lambda { |locale| {:conditions => ["#{translation_class.table_name}.locale = ?", locale.to_s], :joins => :translations} }
155
-
156
157
  private
157
158
 
158
159
  def find_translation(locale)
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class HasTranslationsTest < Test::Unit::TestCase
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: 23
5
- prerelease:
4
+ hash: 21
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 2
10
- version: 0.3.2
9
+ - 3
10
+ version: 0.3.3
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-02-04 00:00:00 +00:00
18
+ date: 2011-02-21 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -27,6 +27,7 @@ extensions: []
27
27
 
28
28
  extra_rdoc_files:
29
29
  - README.md
30
+ - TODO
30
31
  files:
31
32
  - MIT-LICENSE
32
33
  - README.md
@@ -43,6 +44,7 @@ files:
43
44
  - test/schema.rb
44
45
  - test/test_helper.rb
45
46
  - uninstall.rb
47
+ - TODO
46
48
  has_rdoc: true
47
49
  homepage: http://github.com/dmitry/has_translations
48
50
  licenses: []
@@ -73,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
75
  requirements: []
74
76
 
75
77
  rubyforge_project:
76
- rubygems_version: 1.5.0
78
+ rubygems_version: 1.3.7
77
79
  signing_key:
78
80
  specification_version: 3
79
81
  summary: Create translations for your ActiveRecord models.