txdb 3.1.0 → 4.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4323d38729fd41f0867e0763525f9f280a26ad58
4
- data.tar.gz: 323c0b1ed86ca51510590384f34fff999c9c0d0a
3
+ metadata.gz: 26654801172fbb542a042bcb6a0449b76ed7b5e7
4
+ data.tar.gz: deca843a00c592d7f8170c6616e40978b43c99a0
5
5
  SHA512:
6
- metadata.gz: 3a761f7b9869d6110f106feda2da4e7454f241aec2e9cbcea95cf6d33cc01616d908d4db2f8392dfe40af60a922541aa3ab68a94d04c388bbe296e41a437b1be
7
- data.tar.gz: 9d0e0766a4e91bbfbe4abe0b21965de3b87414026c976064d8e4c5a25a7da4266381f398729348f040a883f1fcf1e58780fae54993fa22df5632c14008eebe2f
6
+ metadata.gz: a788e05c2df484b71aa34676f91717d54a53b467f58f0c2c3845b93a5913bddc8afc1291daf21e6d92a9f3922e3a848f6d37d48b48106035a7cf43e12adb611c
7
+ data.tar.gz: 2436f1495010364e154322a7896fd1cccf37ca1f6e2534bd182ef72e0e15692da64ec231011c13b51578eb13bf40d62b01246edfe05a5094169537a09dc70e05
@@ -22,7 +22,7 @@ module Txdb
22
22
  def resource
23
23
  @resource ||= Txgh::TxResource.new(
24
24
  project_slug, resource_slug, Globalize::Backend::RESOURCE_TYPE,
25
- source_lang, source_file, nil, nil
25
+ source_locale, source_file, nil, nil
26
26
  )
27
27
  end
28
28
 
@@ -34,8 +34,8 @@ module Txdb
34
34
  resource_slug_for(table)
35
35
  end
36
36
 
37
- def source_lang
38
- table.source_lang
37
+ def source_locale
38
+ table.database.source_locale
39
39
  end
40
40
 
41
41
  def source_file
data/lib/txdb/database.rb CHANGED
@@ -8,6 +8,7 @@ module Txdb
8
8
 
9
9
  attr_reader :adapter, :backend, :username, :password, :host, :port, :name
10
10
  attr_reader :pool, :transifex_project, :tables, :connection_string
11
+ attr_reader :locales, :source_locale
11
12
 
12
13
  def initialize(options = {})
13
14
  @adapter = options.fetch(:adapter)
@@ -18,6 +19,8 @@ module Txdb
18
19
  @port = options.fetch(:port, DEFAULT_PORT)
19
20
  @name = options.fetch(:name)
20
21
  @pool = options.fetch(:pool, DEFAULT_POOL)
22
+ @locales = options.fetch(:locales)
23
+ @source_locale = options.fetch(:source_locale)
21
24
  @transifex_project = TransifexProject.new(options.fetch(:transifex))
22
25
  @connection_string = ConnectionString.new(options).string
23
26
  @tables = options.fetch(:tables).map do |table_config|
@@ -20,8 +20,8 @@ module Txdb
20
20
 
21
21
  def download_all
22
22
  database.tables.each do |table|
23
- locales.each do |locale|
24
- next if locale == table.source_lang
23
+ database.locales.each do |locale|
24
+ next if locale == database.source_locale
25
25
  download_table(table, locale)
26
26
  end
27
27
  end
@@ -67,11 +67,5 @@ module Txdb
67
67
  Txgh::TxResource.from_api_response(project_slug, resource_hash)
68
68
  end
69
69
  end
70
-
71
- def locales
72
- @locales ||= database.transifex_api
73
- .get_languages(database.transifex_project.project_slug)
74
- .map { |locale| locale['language_code'] }
75
- end
76
70
  end
77
71
  end
@@ -5,7 +5,7 @@ module Txdb
5
5
  class PullHandler < Handler
6
6
  def handle
7
7
  handle_safely do
8
- locales.each do |locale|
8
+ database.locales.each do |locale|
9
9
  downloader.download_table(table, locale)
10
10
  end
11
11
 
@@ -18,12 +18,6 @@ module Txdb
18
18
  def downloader
19
19
  @downloader ||= Downloader.new(database)
20
20
  end
21
-
22
- def locales
23
- database.transifex_api
24
- .get_languages(database.transifex_project.project_slug)
25
- .map { |locale| locale['language_code'] }
26
- end
27
21
  end
28
22
 
29
23
  end
@@ -8,7 +8,7 @@ module Txdb
8
8
  def records_since(counter)
9
9
  super
10
10
  .join(origin_table, column => origin_column)
11
- .where(locale_column => table.source_lang)
11
+ .where(locale_column => table.database.source_locale)
12
12
  end
13
13
 
14
14
  def locale_column
data/lib/txdb/table.rb CHANGED
@@ -3,13 +3,11 @@ require 'txgh'
3
3
  module Txdb
4
4
  class Table
5
5
  attr_reader :database, :name, :columns
6
- attr_reader :source_lang
7
6
 
8
7
  def initialize(database, options = {})
9
8
  @database = database
10
9
  @name = options.fetch(:name)
11
10
  @columns = options.fetch(:columns)
12
- @source_lang = options.fetch(:source_lang)
13
11
  end
14
12
 
15
13
  def connection
data/lib/txdb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Txdb
2
- VERSION = '3.1.0'
2
+ VERSION = '4.0.0'
3
3
  end
@@ -11,11 +11,11 @@ describe Globalize::Writer, globalize_config: true do
11
11
 
12
12
  describe '#write_content' do
13
13
  let(:base_resource) do
14
- # project_slug, resource_slug, type, source_lang, source_file,
14
+ # project_slug, resource_slug, type, source_locale, source_file,
15
15
  # lang_map, translation_file
16
16
  Txgh::TxResource.new(
17
17
  'project_slug', 'resource_slug', Globalize::Backend::RESOURCE_TYPE,
18
- 'source_lang', 'source_file', nil, nil
18
+ 'source_locale', 'source_file', nil, nil
19
19
  )
20
20
  end
21
21
 
data/spec/config_spec.rb CHANGED
@@ -16,7 +16,6 @@ describe Txdb::Config do
16
16
  Txdb::TestConfigurator.base_config.tap do |base_config|
17
17
  base_config[:tables] << {
18
18
  name: 'my_table',
19
- source_lang: 'en',
20
19
  columns: []
21
20
  }
22
21
  end
@@ -69,9 +68,9 @@ describe Txdb::Config do
69
68
  # method loops over more than one db, yielding tables from each
70
69
  config[:databases] << config[:databases].first.merge(
71
70
  database: 'spec/test2.sqlite3',
71
+ source_locale: 'en',
72
72
  tables: [
73
73
  name: 'another_table',
74
- source_lang: 'en',
75
74
  columns: %w(col1 col2)
76
75
  ]
77
76
  )
@@ -33,17 +33,15 @@ describe PullHandler, test_config: true do
33
33
  end
34
34
 
35
35
  it 'downloads the table for each locale' do
36
- locales = [{ 'language_code' => 'es' }, { 'language_code' => 'ja' }]
37
36
  content = { 'phrase' => 'trans' }
38
37
 
39
- expect(database.transifex_api).to receive(:get_languages).and_return(locales)
40
38
  allow(database.transifex_api).to receive(:download).and_return(YAML.dump(content))
41
39
  expect(database.transifex_api).to receive(:get_resources).and_return(
42
40
  [Txdb::TestBackend.resource.to_api_h]
43
41
  )
44
42
 
45
43
  expect { patch('/pull', params) }.to(
46
- change { Txdb::TestBackend.writes.size }.from(0).to(2)
44
+ change { Txdb::TestBackend.writes.size }.from(0).to(2) # ja and es
47
45
  )
48
46
 
49
47
  expect(last_response.status).to eq(200)
@@ -66,7 +64,7 @@ describe PullHandler, test_config: true do
66
64
  end
67
65
 
68
66
  it 'reports errors' do
69
- expect(database.transifex_api).to receive(:get_languages).and_raise('jelly beans')
67
+ expect(database).to receive(:locales).and_raise('jelly beans')
70
68
  patch '/pull', params
71
69
  expect(last_response.status).to eq(500)
72
70
  expect(JSON.parse(last_response.body)).to eq(
@@ -9,7 +9,6 @@ describe AutoIncrementIterator, test_config: true do
9
9
  create_table(:teams) do
10
10
  primary_key :id
11
11
  string :name, translate: true
12
- source_lang 'en'
13
12
  end
14
13
  end
15
14
  end
@@ -16,7 +16,6 @@ describe GlobalizeIterator, test_config: true do
16
16
  integer :team_id
17
17
  string :name, translate: true
18
18
  string :locale
19
- source_lang 'en'
20
19
  end
21
20
  end
22
21
  end
@@ -17,7 +17,6 @@ module Txdb
17
17
  integer :widget_id
18
18
  string :locale
19
19
  string :name, translate: true
20
- source_lang 'en'
21
20
  end
22
21
 
23
22
  block.call if block
@@ -31,7 +31,7 @@ module Txdb
31
31
  def base_resource
32
32
  @base_resource ||= Txgh::TxResource.new(
33
33
  'myproject', 'resource_slug', 'type',
34
- 'source_lang', 'source_file', nil, nil
34
+ 'source_locale', 'source_file', nil, nil
35
35
  )
36
36
  end
37
37
 
@@ -63,6 +63,8 @@ module Txdb
63
63
  username: 'username',
64
64
  password: 'password',
65
65
  name: 'spec/test.sqlite3',
66
+ locales: %w(es ja),
67
+ source_locale: 'en',
66
68
  transifex: {
67
69
  organization: 'myorg',
68
70
  project_slug: 'myproject',
@@ -95,7 +97,7 @@ module Txdb
95
97
  end
96
98
 
97
99
  class TableCreator
98
- attr_reader :name, :database, :columns, :source_lang
100
+ attr_reader :name, :database, :columns
99
101
 
100
102
  def initialize(name, database, &block)
101
103
  @name = name
@@ -117,14 +119,10 @@ module Txdb
117
119
  add_column(column, :integer, *args)
118
120
  end
119
121
 
120
- def source_lang(lang)
121
- @source_lang = lang
122
- end
123
-
124
122
  def table
125
123
  Txdb::Table.new(
126
124
  database, {
127
- name: name.to_s, columns: columns, source_lang: @source_lang
125
+ name: name.to_s, columns: columns
128
126
  }
129
127
  )
130
128
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: txdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-28 00:00:00.000000000 Z
11
+ date: 2016-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport