globalize3 0.1.0 → 0.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- globalize3 (0.1.0.beta2)
4
+ globalize3 (0.2.0.beta1)
5
5
  activemodel (>= 3.0.0)
6
6
  activerecord (>= 3.0.0)
7
+ paper_trail (~> 2)
7
8
 
8
9
  GEM
9
10
  remote: http://rubygems.org/
10
11
  specs:
12
+ abstract (1.0.0)
13
+ actionmailer (3.0.7)
14
+ actionpack (= 3.0.7)
15
+ mail (~> 2.2.15)
16
+ actionpack (3.0.7)
17
+ activemodel (= 3.0.7)
18
+ activesupport (= 3.0.7)
19
+ builder (~> 2.1.2)
20
+ erubis (~> 2.6.6)
21
+ i18n (~> 0.5.0)
22
+ rack (~> 1.2.1)
23
+ rack-mount (~> 0.6.14)
24
+ rack-test (~> 0.5.7)
25
+ tzinfo (~> 0.3.23)
11
26
  activemodel (3.0.7)
12
27
  activesupport (= 3.0.7)
13
28
  builder (~> 2.1.2)
@@ -17,20 +32,52 @@ GEM
17
32
  activesupport (= 3.0.7)
18
33
  arel (~> 2.0.2)
19
34
  tzinfo (~> 0.3.23)
35
+ activeresource (3.0.7)
36
+ activemodel (= 3.0.7)
37
+ activesupport (= 3.0.7)
20
38
  activesupport (3.0.7)
21
39
  archive-tar-minitar (0.5.2)
22
40
  arel (2.0.10)
23
41
  builder (2.1.2)
24
42
  columnize (0.3.2)
25
43
  database_cleaner (0.5.2)
44
+ erubis (2.6.6)
45
+ abstract (>= 1.0.0)
26
46
  i18n (0.5.0)
27
- linecache19 (0.5.11)
47
+ linecache19 (0.5.12)
28
48
  ruby_core_source (>= 0.1.4)
49
+ mail (2.2.19)
50
+ activesupport (>= 2.3.6)
51
+ i18n (>= 0.4.0)
52
+ mime-types (~> 1.16)
53
+ treetop (~> 1.4.8)
54
+ mime-types (1.16)
29
55
  mocha (0.9.10)
30
56
  rake
57
+ paper_trail (2.2.4)
58
+ rails (~> 3)
31
59
  pathname_local (0.0.2)
60
+ polyglot (0.3.1)
61
+ rack (1.2.3)
62
+ rack-mount (0.6.14)
63
+ rack (>= 1.0.0)
64
+ rack-test (0.5.7)
65
+ rack (>= 1.0)
66
+ rails (3.0.7)
67
+ actionmailer (= 3.0.7)
68
+ actionpack (= 3.0.7)
69
+ activerecord (= 3.0.7)
70
+ activeresource (= 3.0.7)
71
+ activesupport (= 3.0.7)
72
+ bundler (~> 1.0)
73
+ railties (= 3.0.7)
74
+ railties (3.0.7)
75
+ actionpack (= 3.0.7)
76
+ activesupport (= 3.0.7)
77
+ rake (>= 0.8.7)
78
+ thor (~> 0.14.4)
32
79
  rake (0.8.7)
33
- ruby-debug-base19 (0.11.24)
80
+ ruby-debug-base19 (0.11.25)
34
81
  columnize (>= 0.3.1)
35
82
  linecache19 (>= 0.5.11)
36
83
  ruby_core_source (>= 0.1.4)
@@ -38,10 +85,13 @@ GEM
38
85
  columnize (>= 0.3.1)
39
86
  linecache19 (>= 0.5.11)
40
87
  ruby-debug-base19 (>= 0.11.19)
41
- ruby_core_source (0.1.4)
88
+ ruby_core_source (0.1.5)
42
89
  archive-tar-minitar (>= 0.5.2)
43
90
  sqlite3-ruby (1.3.2)
44
91
  test_declarative (0.0.5)
92
+ thor (0.14.6)
93
+ treetop (1.4.9)
94
+ polyglot (>= 0.3.1)
45
95
  tzinfo (0.3.27)
46
96
 
47
97
  PLATFORMS
@@ -22,6 +22,13 @@ module Globalize
22
22
  after_create :save_translations!
23
23
  after_update :save_translations!
24
24
 
25
+ if options[:versioning]
26
+ ::ActiveRecord::Base.extend(Globalize::Versioning::PaperTrail)
27
+
28
+ translation_class.has_paper_trail
29
+ delegate :version, :versions, :to => :translation
30
+ end
31
+
25
32
  attr_names.each { |attr_name| translated_attr_accessor(attr_name) }
26
33
  end
27
34
 
@@ -70,8 +70,7 @@ module Globalize
70
70
  end
71
71
 
72
72
  def fetch_attribute(locale, name)
73
- translations ||= record.translations
74
- translation = translations.detect{|t| t.locale == locale}
73
+ translation = record.translation_for(locale)
75
74
  return translation && translation.send(name)
76
75
  end
77
76
 
@@ -45,10 +45,7 @@ module Globalize
45
45
  klass = self.const_set(:Translation, Class.new(Globalize::ActiveRecord::Translation))
46
46
  end
47
47
 
48
- if klass.table_name == 'translations'
49
- klass.set_table_name(translation_options[:table_name])
50
- klass.belongs_to name.underscore.gsub('/', '_')
51
- end
48
+ klass.belongs_to name.underscore.gsub('/', '_')
52
49
  klass
53
50
  end
54
51
  end
@@ -65,7 +65,7 @@ module Globalize
65
65
 
66
66
  def translated_attributes
67
67
  translated_attribute_names.inject({}) do |attributes, name|
68
- attributes.merge(name.to_s => send(name))
68
+ attributes.merge(name.to_s => translation.send(name))
69
69
  end
70
70
  end
71
71
 
@@ -81,7 +81,7 @@ module Globalize
81
81
 
82
82
  def set_translations(options)
83
83
  options.keys.each do |locale|
84
- translation = translations.find_by_locale(locale.to_s) ||
84
+ translation = translation_for(locale) ||
85
85
  translations.build(:locale => locale.to_s)
86
86
  translation.update_attributes!(options[locale])
87
87
  end
@@ -106,6 +106,24 @@ module Globalize
106
106
  return obj
107
107
  end
108
108
 
109
+ def translation
110
+ translation_for(::Globalize.locale)
111
+ end
112
+
113
+ def translation_for(locale)
114
+ @translation_caches ||= {}
115
+ unless @translation_caches[locale]
116
+ _translation = translations.with_locale(locale).first
117
+ _translation ||= translations.build(:locale => locale)
118
+ @translation_caches[locale] = _translation
119
+ end
120
+ @translation_caches[locale]
121
+ end
122
+
123
+ def rollback
124
+ @translation_caches[::Globalize.locale] = translation.previous_version
125
+ end
126
+
109
127
  protected
110
128
 
111
129
  def each_locale_and_translated_attribute
@@ -124,6 +142,7 @@ module Globalize
124
142
 
125
143
  def save_translations!
126
144
  globalize.save_translations!
145
+ @translation_caches = {}
127
146
  end
128
147
 
129
148
  def with_given_locale(attributes, &block)
@@ -136,4 +155,4 @@ module Globalize
136
155
  end
137
156
  end
138
157
  end
139
- end
158
+ end
@@ -24,4 +24,12 @@ module Globalize
24
24
  end
25
25
  end
26
26
  end
27
- end
27
+ end
28
+
29
+ # Setting this will force polymorphic associations to subclassed objects
30
+ # to use their table_name rather than the parent object's table name,
31
+ # which will allow you to get their models back in a more appropriate
32
+ # format.
33
+ #
34
+ # See http://www.ruby-forum.com/topic/159894 for details.
35
+ Globalize::ActiveRecord::Translation.abstract_class = true
@@ -1,5 +1,5 @@
1
1
  module Globalize
2
2
  module Versioning
3
- autoload :VestalVersions, 'globalize/versioning/vestal_versions'
3
+ autoload :PaperTrail, 'globalize/versioning/paper_trail'
4
4
  end
5
5
  end
@@ -0,0 +1,41 @@
1
+ require 'paper_trail'
2
+
3
+ module Globalize
4
+ module Versioning
5
+ module PaperTrail
6
+ # At present this isn't used but we may use something similar in paper trail
7
+ # shortly, so leaving it around to reference easily.
8
+ #def versioned_columns
9
+ #super + self.class.translated_attribute_names
10
+ #end
11
+ end
12
+ end
13
+ end
14
+
15
+ ActiveRecord::Base.class_eval do
16
+ class << self
17
+ def has_paper_trail_with_globalize(*args)
18
+ has_paper_trail_without_globalize(*args)
19
+ include Globalize::Versioning::PaperTrail
20
+ end
21
+ alias_method_chain :has_paper_trail, :globalize
22
+ end
23
+ end
24
+
25
+ Version.class_eval do
26
+
27
+ before_save do |version|
28
+ version.locale = Globalize.locale.to_s
29
+ end
30
+
31
+ def self.locale_conditions_to_sql
32
+ "locale = '#{Globalize.locale.to_s}'"
33
+ end
34
+
35
+ scope :for_this_locale, lambda{ { :conditions => locale_conditions_to_sql } }
36
+
37
+ def sibling_versions_with_locales
38
+ sibling_versions_without_locales.for_this_locale
39
+ end
40
+ alias_method_chain :sibling_versions, :locales
41
+ end
@@ -1,3 +1,3 @@
1
1
  module Globalize3
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0.beta1'
3
3
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: globalize3
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.0
4
+ prerelease: 6
5
+ version: 0.2.0.beta1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sven Fuchs
@@ -39,29 +39,29 @@ dependencies:
39
39
  type: :runtime
40
40
  version_requirements: *id002
41
41
  - !ruby/object:Gem::Dependency
42
- name: database_cleaner
42
+ name: paper_trail
43
43
  prerelease: false
44
44
  requirement: &id003 !ruby/object:Gem::Requirement
45
45
  none: false
46
46
  requirements:
47
- - - "="
47
+ - - ~>
48
48
  - !ruby/object:Gem::Version
49
- version: 0.5.2
50
- type: :development
49
+ version: "2"
50
+ type: :runtime
51
51
  version_requirements: *id003
52
52
  - !ruby/object:Gem::Dependency
53
- name: mocha
53
+ name: database_cleaner
54
54
  prerelease: false
55
55
  requirement: &id004 !ruby/object:Gem::Requirement
56
56
  none: false
57
57
  requirements:
58
- - - ">="
58
+ - - "="
59
59
  - !ruby/object:Gem::Version
60
- version: "0"
60
+ version: 0.5.2
61
61
  type: :development
62
62
  version_requirements: *id004
63
63
  - !ruby/object:Gem::Dependency
64
- name: pathname_local
64
+ name: mocha
65
65
  prerelease: false
66
66
  requirement: &id005 !ruby/object:Gem::Requirement
67
67
  none: false
@@ -72,7 +72,7 @@ dependencies:
72
72
  type: :development
73
73
  version_requirements: *id005
74
74
  - !ruby/object:Gem::Dependency
75
- name: test_declarative
75
+ name: pathname_local
76
76
  prerelease: false
77
77
  requirement: &id006 !ruby/object:Gem::Requirement
78
78
  none: false
@@ -83,7 +83,7 @@ dependencies:
83
83
  type: :development
84
84
  version_requirements: *id006
85
85
  - !ruby/object:Gem::Dependency
86
- name: ruby-debug19
86
+ name: test_declarative
87
87
  prerelease: false
88
88
  requirement: &id007 !ruby/object:Gem::Requirement
89
89
  none: false
@@ -94,7 +94,7 @@ dependencies:
94
94
  type: :development
95
95
  version_requirements: *id007
96
96
  - !ruby/object:Gem::Dependency
97
- name: sqlite3-ruby
97
+ name: ruby-debug19
98
98
  prerelease: false
99
99
  requirement: &id008 !ruby/object:Gem::Requirement
100
100
  none: false
@@ -104,6 +104,17 @@ dependencies:
104
104
  version: "0"
105
105
  type: :development
106
106
  version_requirements: *id008
107
+ - !ruby/object:Gem::Dependency
108
+ name: sqlite3-ruby
109
+ prerelease: false
110
+ requirement: &id009 !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: "0"
116
+ type: :development
117
+ version_requirements: *id009
107
118
  description: "Rails I18n: de-facto standard library for ActiveRecord 3 model/data translation."
108
119
  email: nobody@globalize-rails.org
109
120
  executables: []
@@ -122,7 +133,7 @@ files:
122
133
  - lib/globalize/active_record/migration.rb
123
134
  - lib/globalize/active_record/translation.rb
124
135
  - lib/globalize/active_record.rb
125
- - lib/globalize/versioning/vestal_versions.rb
136
+ - lib/globalize/versioning/paper_trail.rb
126
137
  - lib/globalize/versioning.rb
127
138
  - lib/globalize.rb
128
139
  - lib/globalize3/version.rb
@@ -154,9 +165,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
154
165
  required_rubygems_version: !ruby/object:Gem::Requirement
155
166
  none: false
156
167
  requirements:
157
- - - ">="
168
+ - - ">"
158
169
  - !ruby/object:Gem::Version
159
- version: "0"
170
+ version: 1.3.1
160
171
  requirements: []
161
172
 
162
173
  rubyforge_project: "[none]"
@@ -1,35 +0,0 @@
1
- require 'vestal_versions'
2
-
3
- module Globalize
4
- module Versioning
5
- module VestalVersions
6
- def versioned_columns
7
- super + self.class.translated_attribute_names
8
- end
9
- end
10
- end
11
- end
12
-
13
- ActiveRecord::Base.class_eval do
14
- class << self
15
- def versioned_with_globalize(*args)
16
- versioned_without_globalize(*args)
17
- include Globalize::Versioning::VestalVersions
18
- end
19
- alias_method_chain :versioned, :globalize
20
- end
21
- end
22
-
23
- VestalVersions::Version.class_eval do
24
- before_save do |version|
25
- version.locale = Globalize.locale.to_s
26
- end
27
-
28
- class Condition
29
- def to_sql
30
- "locale = '#{Globalize.locale.to_s}'"
31
- end
32
- end
33
-
34
- default_scope(:conditions => Condition.new)
35
- end