simple_model_translations 0.2.0 → 0.2.1

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_model_translations (0.1.9)
4
+ simple_model_translations (0.2.1)
5
5
  activerecord (~> 3.0.0)
6
6
 
7
7
  GEM
data/README.rdoc CHANGED
@@ -67,6 +67,14 @@ Usage:
67
67
  { :locale => :ru, :name => 'Наука' }
68
68
  ])
69
69
 
70
+ == Fetching records with selected translations
71
+
72
+ If you want (and you probably do want) to fetch only records with specified translation, you can do it now:
73
+
74
+ Article.with_translation(:ru)
75
+
76
+ This code returns an ActiveRecord::Relation object, so you can chain your query furthermore.
77
+
70
78
  == Note on Patches/Pull Requests
71
79
 
72
80
  * Fork the project.
@@ -1,8 +1,13 @@
1
1
  module SimpleModelTranslations
2
2
  module ClassMethods
3
- def with_translations
4
- includes(:translations).where("#{translated_column_name(:id)} IS NOT NULL")
3
+ def with_translations(*args)
4
+ if args.empty?
5
+ includes(:translations).where("#{translated_column_name(:id)} IS NOT NULL")
6
+ else
7
+ includes(:translations).where("#{translated_column_name(:locale)} IN (?)", args)
8
+ end
5
9
  end
10
+ alias with_translation with_translations
6
11
 
7
12
  def translation_class
8
13
  begin
@@ -1,3 +1,3 @@
1
1
  module SimpleModelTranslations
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -1,12 +1,19 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe Article do
4
- it 'should be able to return only records which have translations' do
4
+ it 'should be able to return only records which have translations when called without parameters' do
5
5
  first_article = Article.create!(:slug => 'hello')
6
6
  second_article = Article.create!(:slug => 'world', :name => 'WORLD')
7
7
  Article.with_translations.to_a.should == [second_article]
8
8
  end
9
9
 
10
+ it 'should be able to return only records which have specified translations' do
11
+ first_article = Article.create!(:slug => 'hello', :name => 'WORLD', :locale => :ru)
12
+ second_article = Article.create!(:slug => 'world', :name => 'WORLD', :locale => :en)
13
+ Article.with_translations(:en).to_a.should == [second_article]
14
+ Article.with_translation(:en).to_a.should == [second_article]
15
+ end
16
+
10
17
  it 'should be able to return translation class' do
11
18
  Article.translation_class.should == ArticleTranslation
12
19
  end
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pavel Forkert
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-15 00:00:00 +02:00
18
+ date: 2010-11-16 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency