translatable_records 4.0.0.0 → 4.0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/generators/translation/translation_generator.rb +1 -1
- data/lib/translatable_records/builder.rb +4 -2
- data/lib/translatable_records/railtie.rb +6 -4
- data/lib/translatable_records/version.rb +1 -1
- data/test/dummy/config/database.yml +5 -2
- data/test/dummy/log/development.log +39 -0
- data/test/dummy/log/test.log +91 -0
- data/test/generator_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a26760086d362fabbcb7a67d41bbb2de0f664f1b
|
4
|
+
data.tar.gz: 1f69f8d5d5e078d01f76c9e3a5e1f8900d4bccc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c30b54476adfeef31bbcac47b7ec2f710cb1ab0001542ab6f0531584f85dfe1edc0c102741f99717bf415e0030511b3030c79e0190658f94f9a1a4ff50a3a520
|
7
|
+
data.tar.gz: 7020b8f57c7caa99d661eb18b1f93689b3d91110453b4da87b21f35752f0f5e803de2c29c6a620fcbf9f0c00563dcee5198e58852cb93feec972c91718dbe5da
|
data/README.md
CHANGED
@@ -71,6 +71,12 @@ If you want to save multiple translations:
|
|
71
71
|
<% end %>
|
72
72
|
```
|
73
73
|
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
Any issue, pull request, comment of any kind is more than welcome!
|
77
|
+
|
78
|
+
I will mainly ensure compatibility to PostgreSQL, AWS, Redis, Elasticsearch, FreeBSD and Memcached.
|
79
|
+
|
74
80
|
## Credits
|
75
81
|
|
76
82
|
This gem is maintained and funded by [mmontossi](https://github.com/mmontossi).
|
@@ -2,7 +2,7 @@ require 'rails/generators'
|
|
2
2
|
|
3
3
|
module TranslatableRecords
|
4
4
|
module Generators
|
5
|
-
class TranslationGenerator <
|
5
|
+
class TranslationGenerator < Rails::Generators::NamedBase
|
6
6
|
include Rails::Generators::Migration
|
7
7
|
|
8
8
|
source_root File.expand_path('../templates', __FILE__)
|
@@ -5,11 +5,13 @@ module TranslatableRecords
|
|
5
5
|
|
6
6
|
def initialize(model)
|
7
7
|
@model = model
|
8
|
-
@concern = Module.new
|
8
|
+
@concern = Module.new do
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
include Concern
|
11
|
+
end
|
9
12
|
end
|
10
13
|
|
11
14
|
def define(attributes)
|
12
|
-
model.include Concern
|
13
15
|
ensure_association
|
14
16
|
attributes.each do |attribute|
|
15
17
|
define_writer attribute
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module TranslatableRecords
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
|
4
|
-
initializer 'translatable_records.
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
initializer 'translatable_records.active_record' do
|
5
|
+
ActiveSupport.on_load :active_record do
|
6
|
+
::ActiveRecord::Base.include(
|
7
|
+
TranslatableRecords::Extensions::ActiveRecord::Base
|
8
|
+
)
|
9
|
+
end
|
8
10
|
end
|
9
11
|
|
10
12
|
end
|
@@ -36,4 +36,43 @@ WHERE c.contype = 'f'
|
|
36
36
|
AND t1.relname = 'products'
|
37
37
|
AND t3.nspname = ANY (current_schemas(false))
|
38
38
|
ORDER BY c.conname
|
39
|
+
[0m
|
40
|
+
[1m[36m (2.5ms)[0m [1mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL) [0m
|
41
|
+
[1m[35m (18.6ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
42
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
43
|
+
Migrating to CreateProducts (20130819155126)
|
44
|
+
[1m[35m (0.1ms)[0m BEGIN
|
45
|
+
[1m[36m (1.8ms)[0m [1mCREATE TABLE "products" ("id" serial primary key, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) [0m
|
46
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20130819155126"]]
|
47
|
+
[1m[36m (0.4ms)[0m [1mCOMMIT[0m
|
48
|
+
Migrating to CreateProductTranslations (20161205171056)
|
49
|
+
[1m[35m (0.2ms)[0m BEGIN
|
50
|
+
[1m[36m (2.0ms)[0m [1mCREATE TABLE "product_translations" ("id" serial primary key, "product_id" integer, "locale" character varying, "name" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) [0m
|
51
|
+
[1m[35m (0.7ms)[0m CREATE UNIQUE INDEX "index_product_translations_on_product_id_and_locale" ON "product_translations" ("product_id", "locale")
|
52
|
+
[1m[36mSQL (0.2ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES ($1)[0m [["version", "20161205171056"]]
|
53
|
+
[1m[35m (0.5ms)[0m COMMIT
|
54
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
55
|
+
[1m[35m (1.7ms)[0m SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
|
56
|
+
FROM pg_constraint c
|
57
|
+
JOIN pg_class t1 ON c.conrelid = t1.oid
|
58
|
+
JOIN pg_class t2 ON c.confrelid = t2.oid
|
59
|
+
JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
|
60
|
+
JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
|
61
|
+
JOIN pg_namespace t3 ON c.connamespace = t3.oid
|
62
|
+
WHERE c.contype = 'f'
|
63
|
+
AND t1.relname = 'product_translations'
|
64
|
+
AND t3.nspname = ANY (current_schemas(false))
|
65
|
+
ORDER BY c.conname
|
66
|
+
|
67
|
+
[1m[36m (1.4ms)[0m [1mSELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
|
68
|
+
FROM pg_constraint c
|
69
|
+
JOIN pg_class t1 ON c.conrelid = t1.oid
|
70
|
+
JOIN pg_class t2 ON c.confrelid = t2.oid
|
71
|
+
JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
|
72
|
+
JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
|
73
|
+
JOIN pg_namespace t3 ON c.connamespace = t3.oid
|
74
|
+
WHERE c.contype = 'f'
|
75
|
+
AND t1.relname = 'products'
|
76
|
+
AND t3.nspname = ANY (current_schemas(false))
|
77
|
+
ORDER BY c.conname
|
39
78
|
[0m
|
data/test/dummy/log/test.log
CHANGED
@@ -1456,3 +1456,94 @@ ProductTest: test_persistent
|
|
1456
1456
|
GeneratorsTest: test_install
|
1457
1457
|
----------------------------
|
1458
1458
|
[1m[35m (0.2ms)[0m ROLLBACK
|
1459
|
+
[1m[36mActiveRecord::SchemaMigration Load (26.9ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
1460
|
+
[1m[35m (0.2ms)[0m BEGIN
|
1461
|
+
----------------------------
|
1462
|
+
GeneratorsTest: test_install
|
1463
|
+
----------------------------
|
1464
|
+
[1m[36m (0.1ms)[0m [1mROLLBACK[0m
|
1465
|
+
[1m[35m (0.1ms)[0m BEGIN
|
1466
|
+
----------------------------
|
1467
|
+
ProductTest: test_persistent
|
1468
|
+
----------------------------
|
1469
|
+
[1m[36m (0.2ms)[0m [1mSAVEPOINT active_record_1[0m
|
1470
|
+
[1m[35mProductTranslation Exists (24.8ms)[0m SELECT 1 AS one FROM "product_translations" WHERE ("product_translations"."product_id" IS NULL AND "product_translations"."locale" = 'en') LIMIT 1
|
1471
|
+
[1m[36mProductTranslation Exists (0.3ms)[0m [1mSELECT 1 AS one FROM "product_translations" WHERE ("product_translations"."product_id" IS NULL AND "product_translations"."locale" = 'es') LIMIT 1[0m
|
1472
|
+
[1m[35mSQL (2.0ms)[0m INSERT INTO "products" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id" [["created_at", "2016-12-13 20:29:31.078254"], ["updated_at", "2016-12-13 20:29:31.078254"]]
|
1473
|
+
[1m[36mSQL (1.9ms)[0m [1mINSERT INTO "product_translations" ("locale", "name", "product_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"[0m [["locale", "en"], ["name", "phone"], ["product_id", 52], ["created_at", "2016-12-13 20:29:31.081643"], ["updated_at", "2016-12-13 20:29:31.081643"]]
|
1474
|
+
[1m[35mSQL (0.2ms)[0m INSERT INTO "product_translations" ("locale", "name", "product_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["locale", "es"], ["name", "teléfono"], ["product_id", 52], ["created_at", "2016-12-13 20:29:31.084802"], ["updated_at", "2016-12-13 20:29:31.084802"]]
|
1475
|
+
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
1476
|
+
[1m[35mProduct Load (0.3ms)[0m SELECT "products".* FROM "products" WHERE "products"."id" = $1 LIMIT 1 [["id", 52]]
|
1477
|
+
[1m[36mProductTranslation Load (0.2ms)[0m [1mSELECT "product_translations".* FROM "product_translations" WHERE "product_translations"."product_id" = $1[0m [["product_id", 52]]
|
1478
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
1479
|
+
[1m[36mSQL (0.2ms)[0m [1mDELETE FROM "product_translations" WHERE "product_translations"."id" = $1[0m [["id", 97]]
|
1480
|
+
[1m[35mSQL (0.2ms)[0m DELETE FROM "product_translations" WHERE "product_translations"."id" = $1 [["id", 98]]
|
1481
|
+
[1m[36mSQL (0.1ms)[0m [1mDELETE FROM "products" WHERE "products"."id" = $1[0m [["id", 52]]
|
1482
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
1483
|
+
[1m[36m (0.2ms)[0m [1mSELECT COUNT(*) FROM "product_translations"[0m
|
1484
|
+
[1m[35m (0.1ms)[0m ROLLBACK
|
1485
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
1486
|
+
[1m[35m (0.2ms)[0m BEGIN
|
1487
|
+
----------------------------
|
1488
|
+
GeneratorsTest: test_install
|
1489
|
+
----------------------------
|
1490
|
+
[1m[36m (0.2ms)[0m [1mROLLBACK[0m
|
1491
|
+
[1m[35m (0.1ms)[0m BEGIN
|
1492
|
+
----------------------------
|
1493
|
+
ProductTest: test_persistent
|
1494
|
+
----------------------------
|
1495
|
+
[1m[36m (0.3ms)[0m [1mSAVEPOINT active_record_1[0m
|
1496
|
+
[1m[35mProductTranslation Exists (0.7ms)[0m SELECT 1 AS one FROM "product_translations" WHERE ("product_translations"."product_id" IS NULL AND "product_translations"."locale" = 'en') LIMIT 1
|
1497
|
+
[1m[36mProductTranslation Exists (0.2ms)[0m [1mSELECT 1 AS one FROM "product_translations" WHERE ("product_translations"."product_id" IS NULL AND "product_translations"."locale" = 'es') LIMIT 1[0m
|
1498
|
+
[1m[35mSQL (0.3ms)[0m INSERT INTO "products" ("created_at", "updated_at") VALUES ($1, $2) RETURNING "id" [["created_at", "2016-12-13 20:30:16.263393"], ["updated_at", "2016-12-13 20:30:16.263393"]]
|
1499
|
+
[1m[36mSQL (0.2ms)[0m [1mINSERT INTO "product_translations" ("locale", "name", "product_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"[0m [["locale", "en"], ["name", "phone"], ["product_id", 53], ["created_at", "2016-12-13 20:30:16.264872"], ["updated_at", "2016-12-13 20:30:16.264872"]]
|
1500
|
+
[1m[35mSQL (0.2ms)[0m INSERT INTO "product_translations" ("locale", "name", "product_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["locale", "es"], ["name", "teléfono"], ["product_id", 53], ["created_at", "2016-12-13 20:30:16.265837"], ["updated_at", "2016-12-13 20:30:16.265837"]]
|
1501
|
+
[1m[36m (0.1ms)[0m [1mRELEASE SAVEPOINT active_record_1[0m
|
1502
|
+
[1m[35mProduct Load (0.3ms)[0m SELECT "products".* FROM "products" WHERE "products"."id" = $1 LIMIT 1 [["id", 53]]
|
1503
|
+
[1m[36mProductTranslation Load (0.2ms)[0m [1mSELECT "product_translations".* FROM "product_translations" WHERE "product_translations"."product_id" = $1[0m [["product_id", 53]]
|
1504
|
+
[1m[35m (0.1ms)[0m SAVEPOINT active_record_1
|
1505
|
+
[1m[36mSQL (0.2ms)[0m [1mDELETE FROM "product_translations" WHERE "product_translations"."id" = $1[0m [["id", 99]]
|
1506
|
+
[1m[35mSQL (0.2ms)[0m DELETE FROM "product_translations" WHERE "product_translations"."id" = $1 [["id", 100]]
|
1507
|
+
[1m[36mSQL (0.2ms)[0m [1mDELETE FROM "products" WHERE "products"."id" = $1[0m [["id", 53]]
|
1508
|
+
[1m[35m (0.1ms)[0m RELEASE SAVEPOINT active_record_1
|
1509
|
+
[1m[36m (0.2ms)[0m [1mSELECT COUNT(*) FROM "product_translations"[0m
|
1510
|
+
[1m[35m (0.2ms)[0m ROLLBACK
|
1511
|
+
[1m[36m (19.3ms)[0m [1mCREATE TABLE "schema_migrations" ("version" character varying NOT NULL) [0m
|
1512
|
+
[1m[35m (16.8ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
1513
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
1514
|
+
Migrating to CreateProducts (20130819155126)
|
1515
|
+
[1m[35m (0.1ms)[0m BEGIN
|
1516
|
+
[1m[36m (7.9ms)[0m [1mCREATE TABLE "products" ("id" serial primary key, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) [0m
|
1517
|
+
[1m[35mSQL (0.2ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ($1) [["version", "20130819155126"]]
|
1518
|
+
[1m[36m (6.4ms)[0m [1mCOMMIT[0m
|
1519
|
+
Migrating to CreateProductTranslations (20161205171056)
|
1520
|
+
[1m[35m (11.7ms)[0m BEGIN
|
1521
|
+
[1m[36m (12.9ms)[0m [1mCREATE TABLE "product_translations" ("id" serial primary key, "product_id" integer, "locale" character varying, "name" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL) [0m
|
1522
|
+
[1m[35m (0.8ms)[0m CREATE UNIQUE INDEX "index_product_translations_on_product_id_and_locale" ON "product_translations" ("product_id", "locale")
|
1523
|
+
[1m[36mSQL (0.2ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES ($1)[0m [["version", "20161205171056"]]
|
1524
|
+
[1m[35m (0.6ms)[0m COMMIT
|
1525
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
1526
|
+
[1m[35m (1.7ms)[0m SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
|
1527
|
+
FROM pg_constraint c
|
1528
|
+
JOIN pg_class t1 ON c.conrelid = t1.oid
|
1529
|
+
JOIN pg_class t2 ON c.confrelid = t2.oid
|
1530
|
+
JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
|
1531
|
+
JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
|
1532
|
+
JOIN pg_namespace t3 ON c.connamespace = t3.oid
|
1533
|
+
WHERE c.contype = 'f'
|
1534
|
+
AND t1.relname = 'product_translations'
|
1535
|
+
AND t3.nspname = ANY (current_schemas(false))
|
1536
|
+
ORDER BY c.conname
|
1537
|
+
|
1538
|
+
[1m[36m (1.9ms)[0m [1mSELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete
|
1539
|
+
FROM pg_constraint c
|
1540
|
+
JOIN pg_class t1 ON c.conrelid = t1.oid
|
1541
|
+
JOIN pg_class t2 ON c.confrelid = t2.oid
|
1542
|
+
JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
|
1543
|
+
JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
|
1544
|
+
JOIN pg_namespace t3 ON c.connamespace = t3.oid
|
1545
|
+
WHERE c.contype = 'f'
|
1546
|
+
AND t1.relname = 'products'
|
1547
|
+
AND t3.nspname = ANY (current_schemas(false))
|
1548
|
+
ORDER BY c.conname
|
1549
|
+
[0m
|
data/test/generator_test.rb
CHANGED
@@ -10,7 +10,7 @@ class GeneratorsTest < ::Rails::Generators::TestCase
|
|
10
10
|
end
|
11
11
|
|
12
12
|
test 'install' do
|
13
|
-
self.class.tests TranslationGenerator
|
13
|
+
self.class.tests TranslatableRecords::Generators::TranslationGenerator
|
14
14
|
run_generator %w(product)
|
15
15
|
assert_file 'app/models/product_translation.rb'
|
16
16
|
assert_migration 'db/migrate/create_product_translations.rb'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translatable_records
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
4
|
+
version: 4.0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mmontossi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|