traco 1.2.4 → 1.3.0

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/README.markdown CHANGED
@@ -28,6 +28,8 @@ Write a migration to get database columns with locale suffixes, e.g. `title_sv`
28
28
 
29
29
  Don't create a database column named `title` without a suffix, since Traco will define a method with that name.
30
30
 
31
+ E.g. `title_pt-BR` is also fine, if you need to use that locale format.
32
+
31
33
  Declare the attributes in the model:
32
34
 
33
35
  class Post < ActiveRecord::Base
@@ -70,6 +72,8 @@ The return value will be sorted like `[:title_sv, :title_en, :body_sv, :body_en]
70
72
 
71
73
  And the equivalent methods for `body`, of course.
72
74
 
75
+ Please note that your `translates :title, :body` declaration must be called before you call `locale_columns`. Otherwise you will get an error like "NoMethodError: undefined method `locale\_columns' for #\<Class:0x00000003f69188\>".
76
+
73
77
 
74
78
  ### Disable fallback
75
79
 
@@ -1,7 +1,9 @@
1
1
  module Traco
2
2
  module ClassMethods
3
+ LOCALE_RE = /[a-zA-Z]{2}(?:-[a-zA-Z]{2})?/
4
+
3
5
  def locales_for_attribute(attribute)
4
- re = /\A#{attribute}_([a-z]{2})\z/
6
+ re = /\A#{attribute}_(#{LOCALE_RE})\z/
5
7
 
6
8
  column_names.
7
9
  grep(re) { $1.to_sym }.
@@ -18,7 +20,7 @@ module Traco
18
20
 
19
21
  def human_attribute_name(attribute, options = {})
20
22
  default = super(attribute, options.merge(:default => ""))
21
- if default.blank? && attribute.to_s.match(/\A(\w+)_([a-z]{2})\z/)
23
+ if default.blank? && attribute.to_s.match(/\A(\w+)_(#{LOCALE_RE})\z/)
22
24
  column, locale = $1, $2.to_sym
23
25
  if translates?(column)
24
26
  return "#{super(column, options)} (#{locale_name(locale)})"
data/lib/traco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Traco
2
- VERSION = "1.2.4"
2
+ VERSION = "1.3.0"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -23,8 +23,8 @@ ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":me
23
23
  silence_stream(STDOUT) do
24
24
  ActiveRecord::Schema.define(:version => 0) do
25
25
  create_table :posts, :force => true do |t|
26
- t.string :title_sv, :title_en, :title_fi
27
- t.string :body_sv, :body_en, :body_fi
26
+ t.string :title_sv, :title_en, :title_fi, 'title_pt-BR'
27
+ t.string :body_sv, :body_en, :body_fi, 'body_pt-BR'
28
28
  end
29
29
  end
30
30
  end
data/spec/traco_spec.rb CHANGED
@@ -46,7 +46,7 @@ describe Post, ".locales_for_attribute" do
46
46
  it "lists the locales, default first and then alphabetically" do
47
47
  I18n.default_locale = :fi
48
48
  Post.locales_for_attribute(:title).should == [
49
- :fi, :en, :sv
49
+ :fi, :en, :"pt-BR", :sv,
50
50
  ]
51
51
  end
52
52
  end
@@ -59,15 +59,15 @@ describe Post, ".locale_columns" do
59
59
 
60
60
  it "lists the columns-with-locale for that attribute, default locale first and then alphabetically" do
61
61
  Post.locale_columns(:title).should == [
62
- :title_fi, :title_en, :title_sv
62
+ :title_fi, :title_en, :"title_pt-BR", :title_sv
63
63
  ]
64
64
  end
65
65
 
66
66
  it "supports multiple attributes" do
67
67
  Post.translates :body
68
68
  Post.locale_columns(:body, :title).should == [
69
- :body_fi, :body_en, :body_sv,
70
- :title_fi, :title_en, :title_sv
69
+ :body_fi, :body_en, :"body_pt-BR", :body_sv,
70
+ :title_fi, :title_en, :"title_pt-BR", :title_sv
71
71
  ]
72
72
  end
73
73
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: traco
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-21 00:00:00.000000000 Z
12
+ date: 2013-10-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -143,12 +143,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
143
143
  - - ! '>='
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
+ segments:
147
+ - 0
148
+ hash: -2274355270320966914
146
149
  required_rubygems_version: !ruby/object:Gem::Requirement
147
150
  none: false
148
151
  requirements:
149
152
  - - ! '>='
150
153
  - !ruby/object:Gem::Version
151
154
  version: '0'
155
+ segments:
156
+ - 0
157
+ hash: -2274355270320966914
152
158
  requirements: []
153
159
  rubyforge_project:
154
160
  rubygems_version: 1.8.24