countrizable 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: '039886e40e62d429443e1ade142f7ed8a6b5b3e83a12b7a7fca4fa109b5b3aff'
4
- data.tar.gz: 51e4c3986a33eef57b917eceaa7fd6fb882ffcaabd66ff796fa2e33e72fd48bc
3
+ metadata.gz: b287c8afcc3d89e7f91103d41201f55a19a34ab15716964725655ce2e3d365e9
4
+ data.tar.gz: 891078d325870c2cffefab2acb7a4dcef8e914ce250c286a95615ffb72d0d7ce
5
5
  SHA512:
6
- metadata.gz: d76198119c24f64c9c77b27bd0c45d77c224001f2c443b8ffacc1e8913406fbb09ae72b4c115c28ba46e98fa04f320389b3f8b1b735fd8c14d90ed083fb7eba1
7
- data.tar.gz: 0ffc9b2df18f3d71f878f2ddde6eaea2f4c0d65a33aeb67dd5965ca4a704b8bdba8866be1bf997f63eb864a035bd05d74b5d54c53893b841fb1424f3583af110
6
+ metadata.gz: 417b5795c7316d93a180248288769ccbdf938268d6c23cb51d79146b1f7865bad61940cffb75055447d8eb53651038917f1d86d2c5053875b96c34c80ea26d78
7
+ data.tar.gz: dc8663b7b6d86f8c27e879c4a4a23badc2efefa3df11c4cc993d0d2cd4cc049765f7c1b4f8d836d8c9e4171cdf35e8b510923ab5d035e933bbe91cb561b26791
data/README.md CHANGED
@@ -1,28 +1,98 @@
1
1
  # Countrizable
2
- Short description and motivation.
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
- ## Usage
5
- How to use my plugin.
5
+ ## Requirements
6
+
7
+ * ActiveRecord >= 4.2.0 (see below for installation with ActiveRecord 3.x)
8
+ * I18n
6
9
 
7
10
  ## Installation
8
- Add this line to your application's Gemfile:
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
- And then execute:
15
- ```bash
16
- $ bundle
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
- Or install it yourself as:
20
- ```bash
21
- $ gem install countrizable
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
- ## Contributing
25
- Contribution directions go here.
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
- ## License
28
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
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 :create_country_values_table!, :add_country_value_fields!,
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
 
@@ -1,3 +1,3 @@
1
1
  module Countrizable
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
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.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-01 00:00:00.000000000 Z
11
+ date: 2018-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord