translated_attributes 0.5.5 → 0.6.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/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source :rubygems
2
+
3
+ gem 'activerecord', ENV['AR']
4
+
5
+ group :dev do
6
+ gem 'sqlite3'
7
+ gem 'rake'
8
+ gem 'rspec', '~>2'
9
+ gem 'jeweler'
10
+ end
@@ -0,0 +1,32 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activerecord (2.3.11)
5
+ activesupport (= 2.3.11)
6
+ activesupport (2.3.11)
7
+ diff-lcs (1.1.2)
8
+ git (1.2.5)
9
+ jeweler (1.6.2)
10
+ bundler (~> 1.0)
11
+ git (>= 1.2.5)
12
+ rake
13
+ rake (0.9.2)
14
+ rspec (2.6.0)
15
+ rspec-core (~> 2.6.0)
16
+ rspec-expectations (~> 2.6.0)
17
+ rspec-mocks (~> 2.6.0)
18
+ rspec-core (2.6.4)
19
+ rspec-expectations (2.6.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-mocks (2.6.0)
22
+ sqlite3 (1.3.3)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ activerecord
29
+ jeweler
30
+ rake
31
+ rspec (~> 2)
32
+ sqlite3
data/Rakefile CHANGED
@@ -1,15 +1,20 @@
1
- task :default => :spec
2
- require 'spec/rake/spectask'
3
- Spec::Rake::SpecTask.new {|t| t.spec_opts = ['--color']}
1
+ task :default do
2
+ sh "rspec spec"
3
+ end
4
+
5
+ task :all do
6
+ sh "AR=2.3.12 bundle && bundle exec rake"
7
+ sh "AR=3.0.8 bundle && bundle exec rake"
8
+ sh "AR=3.1.0.rc4 bundle && bundle exec rake"
9
+ end
4
10
 
5
11
  begin
6
- project_name = 'translated_attributes'
7
12
  require 'jeweler'
8
13
  Jeweler::Tasks.new do |gem|
9
- gem.name = project_name
14
+ gem.name = 'translated_attributes'
10
15
  gem.summary = "ActiveRecord/Rails simple translatable attributes"
11
- gem.email = "grosser.michael@gmail.com"
12
- gem.homepage = "http://github.com/grosser/#{project_name}"
16
+ gem.email = "michael@grosser.it"
17
+ gem.homepage = "http://github.com/grosser/#{gem.name}"
13
18
  gem.authors = ["Michael Grosser"]
14
19
  gem.add_dependency ['activerecord']
15
20
  end
@@ -17,4 +22,4 @@ begin
17
22
  Jeweler::GemcutterTasks.new
18
23
  rescue LoadError
19
24
  puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
20
- end
25
+ end
@@ -5,9 +5,9 @@ Validations work like normal with current field (e.g. title) or any translation
5
5
 
6
6
  Usage
7
7
  =====
8
- - As Rails plugin `script/plugin install git://github.com/grosser/translated_attributes.git`
9
- - As gem `sudo gem install translated_attributes`
10
- - generate migrations: `rails generate translated_attributes`(Rails2: [do it by manually](http://github.com/grosser/translated_attributes/blob/master/lib/generators/translated_attributes/templates/migration.rb))
8
+ - As Rails plugin `rails plugin install git://github.com/grosser/translated_attributes.git`
9
+ - As gem `gem install translated_attributes`
10
+ - generate migrations: `rails generate translated_attributes`(Rails2: [do it by hand](http://github.com/grosser/translated_attributes/blob/master/lib/generators/translated_attributes/templates/migration.rb))
11
11
  - `rake db:migrate`
12
12
 
13
13
  Adding attributes:
@@ -40,9 +40,10 @@ Usage with saving works exactly like normal saving, e.g. new/create/update_attri
40
40
  Options
41
41
  =======
42
42
  translated_attributes :title, :heading,
43
- :table_name => 'user_translations', #default is translations
44
- :nil_to_blank => true, #return unfound translations as blank strings ('') instead of nil (default false),
45
- :translatable_name => 'translated' #name of the associated translatable (Product has_many :translations a Translation belongs_to XXX), default is :translatable
43
+ :table_name => 'user_translations', # default is translations
44
+ :nil_to_blank => true, # return unfound translations as blank strings ('') instead of nil (default false),
45
+ :translatable_name => 'translated' # name of the associated translatable (Product has_many :translations a Translation belongs_to XXX), default is :translatable
46
+ :attribute_column => 'attribute' # switch to the old Rails 2 default (default: translated_attribute)
46
47
 
47
48
  Author
48
49
  ======
@@ -50,6 +51,6 @@ Author
50
51
  ###Contributors
51
52
  - [Stefano Diem Benatti](http://github.com/teonimesic)
52
53
 
53
- [Michael Grosser](http://pragmatig.wordpress.com)
54
- grosser.michael@gmail.com
55
- Hereby placed under public domain, do what you want, just do not hold me accountable...
54
+ [Michael Grosser](http://grosser.it)<br/>
55
+ michael@grosser.it<br/>
56
+ Hereby placed under public domain, do what you want, just do not hold me accountable...
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.5
1
+ 0.6.0
@@ -6,7 +6,7 @@ class AddTranslations < ActiveRecord::Migration
6
6
  t.integer :translatable_id, :null=>false
7
7
  t.string :translatable_type, :limit=>40, :null=>false
8
8
  t.string :language, :limit=>2, :null=>false
9
- t.string :attribute, :limit=>40, :null=>false
9
+ t.string :translated_attribute, :limit=>40, :null=>false
10
10
  t.text :text, :null=>false
11
11
  end
12
12
  add_index :translations, [:translatable_id, :translatable_type]
@@ -1,10 +1,13 @@
1
+ require 'active_record'
2
+
1
3
  module TranslatedAttributes
2
4
  module ClassMethods
3
5
  # translated_attributes :title, :description, :table_name=>'my_translations'
4
6
  def translated_attributes(*args)
5
7
  #store options
6
8
  cattr_accessor :translated_attributes_options
7
- options = args.extract_options! || {}
9
+ options = (args.extract_options! || {}).dup
10
+ options[:attribute_column] ||= :translated_attribute
8
11
  self.translated_attributes_options = options.merge(:fields=>args.map(&:to_sym))
9
12
 
10
13
  #create translations class
@@ -117,10 +120,11 @@ module TranslatedAttributes
117
120
  attributes.each do |attribute, value|
118
121
  next if value.blank?
119
122
  next unless self.class.translated_attributes_options[:fields].include? attribute.to_sym
120
- translations.create!(:attribute=>attribute, :text=>value, :language=>locale)
123
+ translations.create!(translated_attributes_options[:attribute_column] => attribute, :text=>value, :language=>locale)
121
124
  end
122
125
  end
123
126
  @translated_attributes_changed = false
127
+ true
124
128
  end
125
129
 
126
130
  private
@@ -129,7 +133,7 @@ module TranslatedAttributes
129
133
  return if new_record? or @db_translations_merged
130
134
  @db_translations_merged = true
131
135
  translations.each do |t|
132
- translated_attributes_for(t.language)[t.attribute] = t.text
136
+ translated_attributes_for(t.language)[t[translated_attributes_options[:attribute_column]]] = t.text
133
137
  end
134
138
  end
135
139
 
@@ -1,5 +1,6 @@
1
1
  ActiveRecord::Schema.define(:version => 1) do
2
2
  create_table :users do |t|
3
+ t.integer :version, :default => 0, :null => false
3
4
  end
4
5
 
5
6
  create_table :products do |t|
@@ -10,7 +11,7 @@ ActiveRecord::Schema.define(:version => 1) do
10
11
  t.integer :translatable_id, :null=>false
11
12
  t.string :translatable_type, :limit=>40, :null=>false
12
13
  t.string :language, :limit=>2, :null=>false
13
- t.string :attribute, :limit=>40, :null=>false
14
+ t.string :translated_attribute, :limit=>40, :null=>false
14
15
  t.text :text, :null=>false
15
16
  end
16
17
  end
@@ -19,6 +20,11 @@ end
19
20
  #create model
20
21
  class User < ActiveRecord::Base
21
22
  translated_attributes :name, :table_name=>:user_translations, :nil_to_blank=>true
23
+ after_save :inc_version
24
+
25
+ def inc_version
26
+ self.version += 1
27
+ end
22
28
  end
23
29
 
24
30
  class Shop < ActiveRecord::Base
@@ -28,4 +34,4 @@ end
28
34
 
29
35
  class Product < ActiveRecord::Base
30
36
  translated_attributes :title, :description
31
- end
37
+ end
@@ -1,6 +1,3 @@
1
- # ---- requirements
2
- require 'rubygems'
3
- require 'spec'
4
1
  require 'active_record'
5
2
 
6
3
  $LOAD_PATH << File.expand_path("../lib", File.dirname(__FILE__))
@@ -15,4 +12,4 @@ ActiveRecord::Base.establish_connection({
15
12
 
16
13
  require File.expand_path("../init", File.dirname(__FILE__))
17
14
 
18
- require 'spec/models'
15
+ require 'spec/models'
@@ -197,6 +197,11 @@ describe 'Translated attributes' do
197
197
  Product.last.title.should == 't2'
198
198
  Product.last.description.should == 'd2'
199
199
  end
200
+
201
+ it "does not cancel callbacks on parent" do
202
+ u = User.create!(:name => 'NAME')
203
+ u.version.should == 1
204
+ end
200
205
  end
201
206
 
202
207
  describe 'classes' do
@@ -319,4 +324,4 @@ describe 'Translated attributes' do
319
324
  Product.new.respond_to?(:new_record?).should == true
320
325
  end
321
326
  end
322
- end
327
+ end
@@ -1,57 +1,51 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{translated_attributes}
8
- s.version = "0.5.5"
8
+ s.version = "0.6.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Grosser"]
12
- s.date = %q{2010-07-15}
13
- s.email = %q{grosser.michael@gmail.com}
14
- s.extra_rdoc_files = [
15
- "README.markdown"
16
- ]
12
+ s.date = %q{2011-06-23}
13
+ s.email = %q{michael@grosser.it}
17
14
  s.files = [
18
- "README.markdown",
19
- "Rakefile",
20
- "VERSION",
21
- "init.rb",
22
- "lib/generators/translated_attributes/USAGE",
23
- "lib/generators/translated_attributes/templates/migration.rb",
24
- "lib/generators/translated_attributes/translated_attributes_generator.rb",
25
- "lib/translated_attributes.rb",
26
- "spec/integration_spec.rb",
27
- "spec/models.rb",
28
- "spec/spec_helper.rb",
29
- "spec/translated_attributes_spec.rb",
30
- "translated_attributes.gemspec"
15
+ "Gemfile",
16
+ "Gemfile.lock",
17
+ "Rakefile",
18
+ "Readme.md",
19
+ "VERSION",
20
+ "init.rb",
21
+ "lib/generators/translated_attributes/USAGE",
22
+ "lib/generators/translated_attributes/templates/migration.rb",
23
+ "lib/generators/translated_attributes/translated_attributes_generator.rb",
24
+ "lib/translated_attributes.rb",
25
+ "spec/integration_spec.rb",
26
+ "spec/models.rb",
27
+ "spec/spec_helper.rb",
28
+ "spec/translated_attributes_spec.rb",
29
+ "translated_attributes.gemspec"
31
30
  ]
32
31
  s.homepage = %q{http://github.com/grosser/translated_attributes}
33
- s.rdoc_options = ["--charset=UTF-8"]
34
32
  s.require_paths = ["lib"]
35
- s.rubygems_version = %q{1.3.6}
33
+ s.rubygems_version = %q{1.6.2}
36
34
  s.summary = %q{ActiveRecord/Rails simple translatable attributes}
37
- s.test_files = [
38
- "spec/models.rb",
39
- "spec/translated_attributes_spec.rb",
40
- "spec/integration_spec.rb",
41
- "spec/spec_helper.rb"
42
- ]
43
35
 
44
36
  if s.respond_to? :specification_version then
45
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
46
37
  s.specification_version = 3
47
38
 
48
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
39
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
40
+ s.add_runtime_dependency(%q<activerecord>, [">= 0"])
49
41
  s.add_runtime_dependency(%q<activerecord>, [">= 0"])
50
42
  else
51
43
  s.add_dependency(%q<activerecord>, [">= 0"])
44
+ s.add_dependency(%q<activerecord>, [">= 0"])
52
45
  end
53
46
  else
54
47
  s.add_dependency(%q<activerecord>, [">= 0"])
48
+ s.add_dependency(%q<activerecord>, [">= 0"])
55
49
  end
56
50
  end
57
51
 
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translated_attributes
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 7
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
- - 5
8
- - 5
9
- version: 0.5.5
8
+ - 6
9
+ - 0
10
+ version: 0.6.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Michael Grosser
@@ -14,32 +15,50 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-07-15 00:00:00 +02:00
18
+ date: 2011-06-23 00:00:00 +02:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
- name: activerecord
22
- prerelease: false
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
+ hash: 3
27
28
  segments:
28
29
  - 0
29
30
  version: "0"
30
31
  type: :runtime
32
+ name: activerecord
31
33
  version_requirements: *id001
34
+ prerelease: false
35
+ - !ruby/object:Gem::Dependency
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 3
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ type: :runtime
46
+ name: activerecord
47
+ version_requirements: *id002
48
+ prerelease: false
32
49
  description:
33
- email: grosser.michael@gmail.com
50
+ email: michael@grosser.it
34
51
  executables: []
35
52
 
36
53
  extensions: []
37
54
 
38
- extra_rdoc_files:
39
- - README.markdown
55
+ extra_rdoc_files: []
56
+
40
57
  files:
41
- - README.markdown
58
+ - Gemfile
59
+ - Gemfile.lock
42
60
  - Rakefile
61
+ - Readme.md
43
62
  - VERSION
44
63
  - init.rb
45
64
  - lib/generators/translated_attributes/USAGE
@@ -56,33 +75,34 @@ homepage: http://github.com/grosser/translated_attributes
56
75
  licenses: []
57
76
 
58
77
  post_install_message:
59
- rdoc_options:
60
- - --charset=UTF-8
78
+ rdoc_options: []
79
+
61
80
  require_paths:
62
81
  - lib
63
82
  required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
64
84
  requirements:
65
85
  - - ">="
66
86
  - !ruby/object:Gem::Version
87
+ hash: 3
67
88
  segments:
68
89
  - 0
69
90
  version: "0"
70
91
  required_rubygems_version: !ruby/object:Gem::Requirement
92
+ none: false
71
93
  requirements:
72
94
  - - ">="
73
95
  - !ruby/object:Gem::Version
96
+ hash: 3
74
97
  segments:
75
98
  - 0
76
99
  version: "0"
77
100
  requirements: []
78
101
 
79
102
  rubyforge_project:
80
- rubygems_version: 1.3.6
103
+ rubygems_version: 1.6.2
81
104
  signing_key:
82
105
  specification_version: 3
83
106
  summary: ActiveRecord/Rails simple translatable attributes
84
- test_files:
85
- - spec/models.rb
86
- - spec/translated_attributes_spec.rb
87
- - spec/integration_spec.rb
88
- - spec/spec_helper.rb
107
+ test_files: []
108
+