traco 4.0.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9060bececc2eb2a4f5bf6fd798f1b6c16523dd21
4
- data.tar.gz: a32a98d4c86f84fc94430cf11ab660fe8993c973
3
+ metadata.gz: 995b6c0b60252d02350da1d58e7ea0268a80a80b
4
+ data.tar.gz: 65c1db0ac8b1036daf10595d5c8745ccf2412aac
5
5
  SHA512:
6
- metadata.gz: 23d5789232d16fa41117707e3502027d4d04328adee5bf8853213dd128ed26badb14f3ad03afbe073424c58d39eb98b46be78998f87d1bf000aa0f0f0d6f9bb5
7
- data.tar.gz: c9461bd93ed5118f51da0862ee929f93df74964c7c56371ca60d88faba043e535b632fcc504e3351c50958f14f130ca2456ad32a06652e4f3dcf5c4ca5a98b6a
6
+ metadata.gz: 7f8fe7b9b21d2ea1ac651bf85d0eaa642e276533973347e8feb7248616632c764a1368a5670f8ee64d2afb519160cdbdec68a53ccb2c730e23c81330db3f657f
7
+ data.tar.gz: 448dff9dd08c1e8fb9c3d4dcfa57bf3fd4e66311ec84c66410fbaea44fac667fe7c8c1add591bb11b6a665648582dd6de59ce35aef604fe14d2a7e3d0444690b
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.0.0
4
+
5
+ * Change `locale_columns` and `locales_for_attribute` to sort current locale first, then default locale (previously, it was default locale first). This makes more sense for our own apps, and hopefully other apps as well.
6
+
3
7
  ## 4.0.0
4
8
 
5
9
  * Drop support for end-of-lifed Ruby 2.1 and 2.2.
data/README.md CHANGED
@@ -52,7 +52,7 @@ You can still use your accessors like `title_sv` and `title_sv=` in forms, valid
52
52
 
53
53
  `.translatable_attributes`: Returns an array like `[:title, :body]`.
54
54
 
55
- `.locale_columns(:title)`: Returns an array like `[:title_sv, :title_en]` sorted with default locale first and then alphabetically. Suitable for looping in forms:
55
+ `.locale_columns(:title)`: Returns an array like `[:title_sv, :title_en]` sorted with current locale first, then default locale, and then alphabetically. Suitable for looping in forms:
56
56
 
57
57
  ```erb
58
58
  <% Post.locale_columns(:title).each do |column| %>
@@ -81,7 +81,7 @@ The return value will be sorted like `[:title_sv, :title_en, :body_sv, :body_en]
81
81
 
82
82
  `.current_locale_column(:title)`: Returns `:title_sv` if `:sv` is the current locale. Suitable for some SQL queries, such as sorting.
83
83
 
84
- `.locales_for_attribute(:title)`: Returns an array like `[:sv, :en]` sorted with default locale first and then alphabetically.
84
+ `.locales_for_attribute(:title)`: Returns an array like `[:sv, :en]` sorted with current locale first, then default locale, and then alphabetically.
85
85
 
86
86
  And the equivalent methods for `body`, of course.
87
87
 
@@ -1,13 +1,13 @@
1
1
  module Traco
2
2
  module ClassMethods
3
3
  def locales_for_attribute(attribute)
4
- traco_cache(attribute, fallback: LocaleFallbacks::DEFAULT_FIRST_FALLBACK).keys
4
+ traco_cache(attribute, fallback: LocaleFallbacks::ANY_FALLBACK).keys
5
5
  end
6
6
 
7
7
  def locale_columns(*attributes)
8
- attributes.each_with_object([]) do |attribute, columns|
9
- columns.concat(_locale_columns_for_attribute(attribute, fallback: LocaleFallbacks::DEFAULT_FIRST_FALLBACK))
10
- end
8
+ attributes.flat_map { |attribute|
9
+ _locale_columns_for_attribute(attribute, fallback: LocaleFallbacks::ANY_FALLBACK)
10
+ }
11
11
  end
12
12
 
13
13
  # Consider this method internal.
@@ -1,3 +1,3 @@
1
1
  module Traco
2
- VERSION = "4.0.0"
2
+ VERSION = "5.0.0"
3
3
  end
@@ -21,8 +21,8 @@ ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
21
21
 
22
22
  ActiveRecord::Schema.define(version: 0) do
23
23
  create_table :posts, force: true do |t|
24
- t.string :title_sv, :title_en, :title_pt_br
25
- t.string :body_sv, :body_en, :body_pt_br
24
+ t.string :title_sv, :title_en, :title_pt_br, :title_de
25
+ t.string :body_sv, :body_en, :body_pt_br, :body_de
26
26
  end
27
27
  end
28
28
 
@@ -84,8 +84,8 @@ describe Post, ".locales_for_attribute" do
84
84
  I18n.locale = :en
85
85
  end
86
86
 
87
- it "lists the locales for that attribute, default locale first and then alphabetically" do
88
- expect(Post.locales_for_attribute(:title)).to eq [ :"pt-BR", :en, :sv ]
87
+ it "lists the locales for that attribute, current locale first, then default locale, and then alphabetically" do
88
+ expect(Post.locales_for_attribute(:title)).to eq [ :en, :"pt-BR", :de, :sv ]
89
89
  end
90
90
 
91
91
  it "doesn't include a locale if there's no corresponding column for it" do
@@ -102,9 +102,9 @@ describe Post, ".locale_columns" do
102
102
  I18n.locale = :en
103
103
  end
104
104
 
105
- it "lists the columns-with-locale for that attribute, default locale first and then alphabetically" do
105
+ it "lists the columns-with-locale for that attribute, current locale first, then default locale, and then alphabetically" do
106
106
  expect(Post.locale_columns(:title)).to eq [
107
- :title_pt_br, :title_en, :title_sv
107
+ :title_en, :title_pt_br, :title_de, :title_sv,
108
108
  ]
109
109
  end
110
110
 
@@ -114,12 +114,12 @@ describe Post, ".locale_columns" do
114
114
  expect(Post.locale_columns(:title)).not_to include(:title_ru)
115
115
  end
116
116
 
117
- it "supports multiple attributes" do
118
- Post.translates :body
117
+ it "supports multiple attributes" do
118
+ Post.translates :body
119
119
 
120
120
  expect(Post.locale_columns(:body, :title)).to eq [
121
- :body_pt_br, :body_en, :body_sv,
122
- :title_pt_br, :title_en, :title_sv,
121
+ :body_en, :body_pt_br, :body_de, :body_sv,
122
+ :title_en, :title_pt_br, :title_de, :title_sv,
123
123
  ]
124
124
  end
125
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traco
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-11 00:00:00.000000000 Z
11
+ date: 2018-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord