localizable_model 0.0.1 → 0.5.0

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: a2cfa395a30db8062f472845636f6fbfe118c7d5
4
- data.tar.gz: 8d6e6c2b743b69648ef92990260e18de313c6672
3
+ metadata.gz: f922dccacb3ed524ee9c233afff9e824b5b08533
4
+ data.tar.gz: b1dc4c6662be10b0037206349e0ae0e116a31ee2
5
5
  SHA512:
6
- metadata.gz: bb2536b98ca7556e2fcbdfe26faadfd13b8912fd9e9499f2a4858fa3be2e8f1a289a57aaa59ca0128ca9982a54099017941b8b50d3371c402ed1fc4ea29badb3
7
- data.tar.gz: 35a202be39a802512a60f138acbd56a23f74de8d8118a205fbb8aedbdc9ca7d9a518bf8dd91538d9d957a3f99a281db13afe41f209e77e3ca2459251dbae5a56
6
+ metadata.gz: 6e5c1418be91c5a6bdecc7aaaae5a8e17f645777cce32ae1b8a5faf58b10511dc2f18d3223850540716de6a881c34d753f8393e013a75e4f4ae5cda314aae4a7
7
+ data.tar.gz: 8b813cb237e9a622802e9576639303d87b1d72c00b3326b25e84d2108d8f8bd615c60820daaf81c18ebbdbcb2babe3b6337a1c76c6ce2a9134cd3fe63532525c
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
1
  # LocalizableModel
2
2
 
3
+ LocalizableModel allows any ActiveRecord model to have localized attributes.
4
+
3
5
  [![Build Status](https://travis-ci.org/kord-as/localizable_model.svg?branch=master)](https://travis-ci.org/kord-as/localizable_model) [![Code Climate](https://codeclimate.com/github/kord-as/localizable_model/badges/gpa.svg)](https://codeclimate.com/github/kord-as/localizable_model) [![Test Coverage](https://codeclimate.com/github/kord-as/localizable_model/badges/coverage.svg)](https://codeclimate.com/github/kord-as/localizable_model) [![Dependency Status](https://gemnasium.com/kord-as/localizable_model.svg)](https://gemnasium.com/kord-as/localizable_model)
4
6
 
5
- ## Usage
7
+ ## Installation
6
8
 
7
9
  Add the `localizable_model` gem to your Gemfile:
8
10
 
@@ -16,6 +18,64 @@ Generate the migration:
16
18
  bin/rails g localizable_model:migration
17
19
  ```
18
20
 
21
+ ## Usage
22
+
23
+ You can now define localizable attributes on your model:
24
+
25
+ ``` ruby
26
+ class Page < ActiveRecord::Base
27
+ localizable do
28
+ attribute :name
29
+ attribute :body
30
+ end
31
+ end
32
+ ```
33
+
34
+ You can also use a dictionary. This will let you define attributes dynamically
35
+ at runtime.
36
+
37
+ ``` ruby
38
+ class Page < ActiveRecord::Base
39
+ localizable do
40
+ dictionary lambda { Page.localizable_attrs }
41
+ end
42
+
43
+ class << self
44
+ def localizable_attrs
45
+ [:foo, :bar, :baz]
46
+ end
47
+ end
48
+ end
49
+ ```
50
+
51
+ Usage examples:
52
+
53
+ ``` ruby
54
+ page = Page.create(locale: "en", name: "Hello")
55
+ page.name? # => true
56
+ page.name.to_s # => "Hello"
57
+ ```
58
+
59
+ To get a localized version of a page, call `.localize` on it:
60
+
61
+ ``` ruby
62
+ page = Page.first.localize("en")
63
+ ```
64
+
65
+ `.localize` can also take a block argument:
66
+
67
+ ``` ruby
68
+ page.localize("nb") do |p|
69
+ p.locale # => "nb"
70
+ end
71
+ p.locale # => "en"
72
+ ```
73
+
74
+ Multiple locales can be updated at the same time:
75
+
76
+ ``` ruby
77
+ page.name = { en: "Hello", fr: "Bonjour" }
78
+ ```
19
79
 
20
80
  ## License
21
81
 
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module LocalizableModel
4
- VERSION = "0.0.1".freeze unless LocalizableModel.const_defined?("VERSION")
4
+ VERSION = "0.5.0".freeze unless LocalizableModel.const_defined?("VERSION")
5
5
  end
@@ -6,6 +6,9 @@ class CreateLocalizations < ActiveRecord::Migration
6
6
  t.string :locale
7
7
  t.text :value, limit: 16_777_215
8
8
  t.timestamps null: false
9
+ t.index([:localizable_id, :localizable_type, :name, :locale],
10
+ name: "index_localizations_on_locale")
11
+ t.index [:localizable_id, :localizable_type]
9
12
  end
10
13
  end
11
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localizable_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Inge Jørgensen