countrizable 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/README.md +84 -14
- data/lib/countrizable/active_record/migration.rb +1 -1
- data/lib/countrizable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b287c8afcc3d89e7f91103d41201f55a19a34ab15716964725655ce2e3d365e9
|
4
|
+
data.tar.gz: 891078d325870c2cffefab2acb7a4dcef8e914ce250c286a95615ffb72d0d7ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 417b5795c7316d93a180248288769ccbdf938268d6c23cb51d79146b1f7865bad61940cffb75055447d8eb53651038917f1d86d2c5053875b96c34c80ea26d78
|
7
|
+
data.tar.gz: dc8663b7b6d86f8c27e879c4a4a23badc2efefa3df11c4cc993d0d2cd4cc049765f7c1b4f8d836d8c9e4171cdf35e8b510923ab5d035e933bbe91cb561b26791
|
data/README.md
CHANGED
@@ -1,28 +1,98 @@
|
|
1
1
|
# Countrizable
|
2
|
-
|
2
|
+
Countrizable is a gem to use on top of ruby on rails to add model contents depending on country.
|
3
|
+
Inspired in [![Globalize]](https://github.com/globalize/globalize)
|
3
4
|
|
4
|
-
##
|
5
|
-
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
* ActiveRecord >= 4.2.0 (see below for installation with ActiveRecord 3.x)
|
8
|
+
* I18n
|
6
9
|
|
7
10
|
## Installation
|
8
|
-
|
11
|
+
|
12
|
+
To install the ActiveRecord 4.2.x compatible version of Globalize with its default setup, just use:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem install countrizable
|
16
|
+
```
|
17
|
+
|
18
|
+
When using bundler put this in your Gemfile:
|
9
19
|
|
10
20
|
```ruby
|
11
21
|
gem 'countrizable'
|
12
22
|
```
|
13
23
|
|
14
|
-
|
15
|
-
|
16
|
-
|
24
|
+
## Model country attributes
|
25
|
+
|
26
|
+
Model translations allow you to translate your models' attribute values. E.g.
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
class Product < ActiveRecord::Base
|
30
|
+
country_attribure :price
|
31
|
+
country_attribure :currency
|
32
|
+
end
|
17
33
|
```
|
18
34
|
|
19
|
-
|
20
|
-
|
21
|
-
|
35
|
+
Allows you to translate the attributes :title and :text per locale:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
Countrizable.country_code = :uk
|
39
|
+
product.price # => 3.00
|
40
|
+
product.currency # => Pound
|
41
|
+
|
42
|
+
Countrizable.country_code = :de
|
43
|
+
product.price # => 3.60
|
44
|
+
product.currency # => Euro
|
22
45
|
```
|
23
46
|
|
24
|
-
|
25
|
-
|
47
|
+
You can also set translations with mass-assignment by specifying the locale:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
product.attributes = { price: 4.5, country_code: :uk }
|
51
|
+
```
|
52
|
+
|
53
|
+
In order to make this work, you'll need to add the appropriate country attribute tables.
|
54
|
+
Countrizable comes with a handy helper method to help you do this.
|
55
|
+
It's called `create_country_value_table!`. Here's an example:
|
56
|
+
|
57
|
+
Note that your migrations can use `create_country_value_table!` and `drop_country_value_table!`
|
58
|
+
only inside the `up` and `down` instance methods, respectively. You cannot use `create_country_value_table!`
|
59
|
+
and `drop_country_value_table!` inside the `change` instance method.
|
60
|
+
|
61
|
+
### Creating country value tables
|
62
|
+
|
63
|
+
Also note that before you can create a translation table, you have to define the translated attributes via `country_attribute` in your model as shown above.
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
class CreateProducts < ActiveRecord::Migration
|
67
|
+
def change
|
68
|
+
create_table :products do |t|
|
69
|
+
t.timestamps
|
70
|
+
end
|
71
|
+
|
72
|
+
#creating country value tables
|
73
|
+
reversible do |dir|
|
74
|
+
dir.up do
|
75
|
+
Post.create_country_value_table!({
|
76
|
+
:price => :decimal, default: 0, :precision => 8, :scale => 2,
|
77
|
+
:currency => :string
|
78
|
+
})
|
79
|
+
end
|
80
|
+
|
81
|
+
dir.down do
|
82
|
+
Post.drop_country_value_table!
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
#compatible with globalize gem
|
87
|
+
reversible do |dir|
|
88
|
+
dir.up do
|
89
|
+
Post.create_translation_table! :title => :string, :text => :text
|
90
|
+
end
|
26
91
|
|
27
|
-
|
28
|
-
|
92
|
+
dir.down do
|
93
|
+
Post.drop_translation_table!
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
```
|
@@ -7,7 +7,7 @@ module Countrizable
|
|
7
7
|
@countrizable_migrator ||= Migrator.new(self)
|
8
8
|
end
|
9
9
|
|
10
|
-
delegate :
|
10
|
+
delegate :create_country_value_table!, :add_country_value_fields!,
|
11
11
|
:drop_country_value_table!, :country_value_index_name,
|
12
12
|
:country_value_country_code_index_name, :to => :countrizable_migrator
|
13
13
|
|
data/lib/countrizable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: countrizable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iván Guillén
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|