globalize-accessors 0.1.0 → 0.1.1

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: 7defb92b751ffc09ccb3dfe0dc0c8df08488e1dd
4
- data.tar.gz: a620943951380974008d867118a3f82ccd6c505b
3
+ metadata.gz: 367386484b2db24a7568c6227d7ed4297cc2c5ee
4
+ data.tar.gz: 3c123202c983f00e83277d512f21b3c55af51795
5
5
  SHA512:
6
- metadata.gz: 0c29be7111eafd912a409f0e5fd35b8d67d36ed2fff702c7505e79c5530c824eed6b829bd142d65105d0bb035e64326b23ce0b6fdfbeb176d8f60ef84b2d702a
7
- data.tar.gz: 26615c51f8318312099d7ff03704d516d627b51d1c71e6b960f8c3d0b8ba3d73064e88132bf6d301ef3d7c150e7b236d0fd051259aa7e00fd9a233ebf76023ba
6
+ metadata.gz: 1226e51ce8c7c56608aae8555bf34fd1b5b076f988a9188636d10b3bfd1c18456ef6afb4ab2d5f4679aa7ab963a25cc0ddc36a064c84496240621bd7ce6f10a5
7
+ data.tar.gz: 329f021d11c44d77b566778b3fa93c0e59e92b77300cc2e2e2b2cf430d6591a108d0d3b7f4ad1896f08b7a5b3b4cb6a3f0e5af7540f57fdf2836ed963d162b1b
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ before_script:
3
+ - "cp test/db/database.yml.travis test/db/database.yml"
4
+ script: "bundle exec rake"
5
+ env:
6
+ - RAILS_3=true
7
+ - RAILS_4=true
8
+ rvm:
9
+ - 2.0.0
10
+ - 1.9.3
@@ -14,7 +14,11 @@ Gem::Specification.new do |s|
14
14
  s.required_rubygems_version = ">= 1.3.6"
15
15
  s.rubyforge_project = "globalize-accessors"
16
16
 
17
- s.add_dependency "globalize3", "~> 0.3.0"
17
+ if ENV['RAILS_3']
18
+ s.add_dependency "globalize3", "~> 0.3.0"
19
+ else
20
+ s.add_dependency "globalize", "~> 4.0.0.alpha.1"
21
+ end
18
22
 
19
23
  s.add_development_dependency "bundler", "~> 1.3.5"
20
24
  s.add_development_dependency "rake", "~> 0.9.2"
@@ -1,4 +1,4 @@
1
- require 'globalize3'
1
+ require 'globalize'
2
2
 
3
3
  module GlobalizeAccessors
4
4
  attr_reader :globalize_locales
@@ -1,3 +1,3 @@
1
1
  module GlobalizeAccessors
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -1,56 +1,64 @@
1
- = Globalize Accessors
1
+ # Globalize Accessors [![Build Status](https://travis-ci.org/globalize/globalize-accessors.png)](https://travis-ci.org/globalize/globalize-accessors)
2
2
 
3
- == Introduction
3
+ ## Introduction
4
4
 
5
5
  Generator of accessor methods for models using Globalize. Use globalize-accessors with a list of translated fields you want easily access to and extra :locales array listing locales for which you want the accessors to be generated.
6
6
 
7
7
  This way a single form can be used to edit given model fields with all anticipated translations.
8
8
 
9
- Note that globalize-accessors is currently only compatible with the globalize3 gem for Rails 3.x.
9
+ `globalize-accessors` is compatible with both Rails 3.x and Rails 4.
10
10
 
11
11
 
12
- == Installation
12
+ ## Installation
13
13
 
14
14
  gem install globalize-accessors
15
15
 
16
- == Example
16
+ ## Example
17
17
 
18
18
  Definition like this:
19
19
 
20
- class Product
21
- translates :title, :description
22
- globalize_accessors :locales => [:en, :pl], :attributes => [:title]
23
- end
20
+ ````ruby
21
+ class Product
22
+ translates :title, :description
23
+ globalize_accessors :locales => [:en, :pl], :attributes => [:title]
24
+ end
25
+ ````
24
26
 
25
27
  Gives you access to methods: `title_pl`, `title_en`, `title_pl=`, `title_en=` (and a similar set of description_* methods). They work seamlessly with Globalize (not even touching the "core" title, title= methods used by Globalize itself).
26
28
 
27
29
  `:locales` and `:attributes` are optional. Default values are:
28
30
 
31
+ ````ruby
29
32
  :locales => I18n.available_locales
30
33
  :attributes => translated_attribute_names
34
+ ````
31
35
 
32
36
  which means that skipping all options will generate you accessor method for all translated fields and available languages.
33
37
 
34
38
  You can also get the accessor locales for a class with the `globalize_locales` method:
35
39
 
40
+ ````ruby
36
41
  Product.globalize_locales # => [:en, :pl]
42
+ ````
37
43
 
38
- == Always define accessors
44
+ ## Always define accessors
39
45
 
40
46
  If you wish to always define accessors and don't want to call the globalize_accessors method in every class, you can extend ActiveRecord::Base with a module:
41
47
 
42
- module TranslatesWithAccessors
43
-
44
- def translates(*params)
45
- options = params.extract_options!
46
- options.reverse_merge!(:globalize_accessors => true)
47
- accessors = options.delete(:globalize_accessors)
48
- super
49
- globalize_accessors if accessors
50
- end
48
+ ````ruby
49
+ module TranslatesWithAccessors
51
50
 
51
+ def translates(*params)
52
+ options = params.extract_options!
53
+ options.reverse_merge!(:globalize_accessors => true)
54
+ accessors = options.delete(:globalize_accessors)
55
+ super
56
+ globalize_accessors if accessors
52
57
  end
53
58
 
54
- == Licence
59
+ end
60
+ ````
61
+
62
+ ## Licence
55
63
 
56
64
  Copyright (c) 2009-2013 Tomek "Tomash" Stachewicz (http://tomash.wrug.eu), Robert Pankowecki (http://robert.pankowecki.pl) released under the MIT license
@@ -0,0 +1,21 @@
1
+ sqlite3:
2
+ adapter: sqlite3
3
+ dbfile: globalize.sqlite3
4
+ database: globalize.sqlite3
5
+ sqlite3mem:
6
+ adapter: sqlite3
7
+ dbfile: ":memory:"
8
+ database: globalize.sqlite3
9
+ postgresql:
10
+ adapter: postgresql
11
+ username: postgres
12
+ password: postgres
13
+ database: globalize
14
+ min_messages: ERROR
15
+ mysql:
16
+ adapter: mysql
17
+ host: localhost
18
+ username: root
19
+ password:
20
+ database: globalize
21
+
@@ -15,7 +15,7 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
15
15
 
16
16
  class UnitWithAttrAccessible < ActiveRecord::Base
17
17
  self.table_name = :units
18
- attr_accessible :name
18
+ attr_accessible :name if ENV['RAILS_3']
19
19
  translates :name, :title
20
20
  globalize_accessors
21
21
  end
@@ -96,14 +96,16 @@ class GlobalizeAccessorsTest < ActiveSupport::TestCase
96
96
  assert_equal "Name pl", u.name_pl
97
97
  end
98
98
 
99
- test "whitelist locale accessors if the original attribute is whitelisted" do
100
- u = UnitWithAttrAccessible.new()
101
- u.update_attributes(:name => "Name en", :name_pl => "Name pl", :title => "Title en", :title_pl => "Title pl")
99
+ if ENV['RAILS_3']
100
+ test "whitelist locale accessors if the original attribute is whitelisted" do
101
+ u = UnitWithAttrAccessible.new()
102
+ u.update_attributes(:name => "Name en", :name_pl => "Name pl", :title => "Title en", :title_pl => "Title pl")
102
103
 
103
- assert_equal "Name en", u.name
104
- assert_equal "Name pl", u.name_pl
105
- assert_nil u.title
106
- assert_nil u.title_pl
104
+ assert_equal "Name en", u.name
105
+ assert_equal "Name pl", u.name_pl
106
+ assert_nil u.title
107
+ assert_nil u.title_pl
108
+ end
107
109
  end
108
110
 
109
111
  test "globalize locales on class without locales specified in options" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: globalize-accessors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomasz Stachewicz
@@ -12,22 +12,22 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-10-16 00:00:00.000000000 Z
15
+ date: 2013-10-22 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
- name: globalize3
18
+ name: globalize
19
19
  requirement: !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: 0.3.0
23
+ version: 4.0.0.alpha.1
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- version: 0.3.0
30
+ version: 4.0.0.alpha.1
31
31
  - !ruby/object:Gem::Dependency
32
32
  name: bundler
33
33
  requirement: !ruby/object:Gem::Requirement
@@ -82,14 +82,16 @@ extensions: []
82
82
  extra_rdoc_files: []
83
83
  files:
84
84
  - .gitignore
85
+ - .travis.yml
85
86
  - Gemfile
86
87
  - MIT-LICENSE
87
- - README.rdoc
88
88
  - Rakefile
89
89
  - globalize-accessors.gemspec
90
90
  - lib/globalize-accessors.rb
91
91
  - lib/globalize-accessors/version.rb
92
+ - readme.md
92
93
  - test/db/database.yml.example
94
+ - test/db/database.yml.travis
93
95
  - test/db/schema.rb
94
96
  - test/globalize_accessors_test.rb
95
97
  - test/test_helper.rb