simple_model_translations 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -16,6 +16,15 @@ So, you'll need the following models to achieve this behaviour:
16
16
  translation_for :article
17
17
  end
18
18
 
19
+ or, if you are not going to add some additional behavior to translation class (for example, validations),
20
+ you can use translation class, created for you by default:
21
+
22
+ class Article < ActiveRecord::Base
23
+ translates :name, :content
24
+ end
25
+
26
+ ArticleTranslation will be generated automagically :)
27
+
19
28
  Also, you'll need a migration:
20
29
 
21
30
  create_table(:article_translations) do |t|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -50,10 +50,6 @@ module SimpleModelTranslations
50
50
  include SimpleModelTranslations::Attributes
51
51
  extend SimpleModelTranslations::ClassMethods
52
52
 
53
- # unless Kernel.const_get(class_name)
54
- # klass = Kernel.const_set(class_name.to_sym, Class.new(ActiveRecord::Base))
55
- # klass.translation_for(self.name.underscore.to_sym)
56
- # end
57
53
  has_many :translations, :class_name => translation_class_name, :dependent => :destroy, :autosave => true
58
54
 
59
55
  if options[:accepts_nested_attributes]
@@ -5,7 +5,13 @@ module SimpleModelTranslations
5
5
  end
6
6
 
7
7
  def translation_class
8
- Module.const_get(translation_class_name)
8
+ begin
9
+ klass = Module.const_get(translation_class_name.to_sym)
10
+ rescue NameError => e
11
+ klass = Module.const_set(translation_class_name.to_sym, Class.new(ActiveRecord::Base))
12
+ klass.translation_for(self.name.underscore.to_sym)
13
+ end
14
+ klass
9
15
  end
10
16
 
11
17
  def translation_class_name
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{simple_model_translations}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Pavel Forkert"]
data/spec/data/models.rb CHANGED
@@ -14,3 +14,7 @@ end
14
14
  class PostTranslation < ActiveRecord::Base
15
15
  translation_for :post
16
16
  end
17
+
18
+ class Tag < ActiveRecord::Base
19
+ translates :name
20
+ end
@@ -24,6 +24,11 @@ describe Article do
24
24
  I18n.locale = :de
25
25
  article.name.should == 'Hello'
26
26
  end
27
+
28
+ it "should create translation class automatically if it doesn't exists" do
29
+ Tag.translation_class.should_not be_nil
30
+ Tag.translation_class.table_name.should == 'tag_translations'
31
+ end
27
32
  end
28
33
 
29
34
  describe ArticleTranslation do
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,6 @@ Bundler.require(:default, :test)
5
5
 
6
6
  require 'rspec'
7
7
  require 'shoulda'
8
- require 'factory_girl'
9
8
  require 'active_record'
10
9
  require 'simple_model_translations'
11
10
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_model_translations
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pavel Forkert