table_saw 1.0.1 → 1.1.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
  SHA256:
3
- metadata.gz: bb6ffaafa1117b800a4fa6282187dddc2b6da2c61579c6b5940b21269451c431
4
- data.tar.gz: ff3ea8303a25046b6f2befdb292750d70e25487f820192522eefe799d4eb698f
3
+ metadata.gz: 33d3ff20492080ac1eb74a93466aa8c1d2b6f52b192b1b9fee8744a1755e6e2c
4
+ data.tar.gz: c1f5f2908a7b1f894e56696da3a3d37efb28ad9567527dc65ec57a7991506c11
5
5
  SHA512:
6
- metadata.gz: 5f42184e9ccf6f9b576f47503f998e84d0a219101f15b5923b4bfdf4d5852f76b79feae4c17f00286e54d20f20ce1f4e0121b807fdba79047b7276946a3a723f
7
- data.tar.gz: c391ba301f9be2aac7616e3f9f7843e60b5d12d80d4dd18549185ee1aa472f4c9148f700be65f34b7415266565faff11095ef9dd9d5a8fe9e3ec87151f9938b4
6
+ metadata.gz: 260d2f1af458bc4ed939a647e206cd1bb9cab56211ea1031e2abb5c002fa0e22981b497d6f6a350207d540f5be522600ae2f1b87cc880476b136ffb05219497f
7
+ data.tar.gz: a0e4e17955719d75410b173c8a85052d036c434fb0c88da3a1cdd623a75c7b3fca3eaa2c9e1f756f3ffa8440151eb2d94b9c9a5d9e2facbeeb036b98b3f19a76
data/.rubocop.yml CHANGED
@@ -9,6 +9,10 @@ Layout/MultilineMethodCallIndentation:
9
9
  Metrics/LineLength:
10
10
  Max: 120
11
11
 
12
+ Naming/PredicateName:
13
+ NameWhitelist:
14
+ - has_many
15
+
12
16
  Style/Documentation:
13
17
  Enabled: false
14
18
 
data/.travis.yml CHANGED
@@ -18,4 +18,6 @@ script:
18
18
  after_script:
19
19
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
20
20
  addons:
21
- postgresql: "9.3"
21
+ postgresql: "9.6"
22
+ services:
23
+ - postgresql
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- table_saw (1.0.1)
4
+ table_saw (1.1.0)
5
5
  connection_pool
6
6
  pg
7
7
  thor
@@ -3,13 +3,14 @@
3
3
  module TableSaw
4
4
  module DependencyGraph
5
5
  class AddDirective
6
- attr_reader :table_name, :partial
6
+ attr_reader :table_name, :partial, :has_many
7
7
  attr_accessor :ids
8
8
 
9
- def initialize(table_name, ids: [], partial: true)
9
+ def initialize(table_name, ids: [], partial: true, has_many: [])
10
10
  @table_name = table_name
11
11
  @ids = ids
12
12
  @partial = partial
13
+ @has_many = has_many
13
14
  end
14
15
 
15
16
  alias partial? partial
@@ -12,7 +12,8 @@ module TableSaw
12
12
 
13
13
  def call
14
14
  manifest.tables.values.sort_by { |t| t.partial? ? 1 : 0 }.each do |table|
15
- add TableSaw::DependencyGraph::AddDirective.new(table.name, ids: select_ids(table), partial: table.partial?)
15
+ add TableSaw::DependencyGraph::AddDirective.new(table.name, ids: select_ids(table), partial: table.partial?,
16
+ has_many: table.has_many)
16
17
  end
17
18
 
18
19
  records
@@ -26,13 +26,16 @@ module TableSaw
26
26
  TableSaw.information_schema.has_many.fetch(directive.table_name, [])
27
27
  end
28
28
 
29
+ # rubocop:disable Metrics/AbcSize
29
30
  def valid_associations
30
31
  associations.select do |table, _column|
31
32
  next false if directive.partial? && !TableSaw.information_schema.primary_keys.key?(table)
33
+ next true if directive.has_many.include?(table)
32
34
 
33
- manifest.has_many_mapping.fetch(directive.table_name, []).include?(table)
35
+ manifest.has_many.fetch(directive.table_name, []).include?(table)
34
36
  end
35
37
  end
38
+ # rubocop:enable Metrics/AbcSize
36
39
 
37
40
  def query_result(table, column)
38
41
  return [] unless directive.selectable?
@@ -6,11 +6,9 @@ module TableSaw
6
6
  foreign_key_relationships.belongs_to
7
7
  end
8
8
 
9
- # rubocop:disable Naming/PredicateName
10
9
  def has_many
11
10
  foreign_key_relationships.has_many
12
11
  end
13
- # rubocop:enable Naming/PredicateName
14
12
 
15
13
  def primary_keys
16
14
  @primary_keys ||= TableSaw::Queries::PrimaryKeys.new.call
@@ -27,6 +27,10 @@ module TableSaw
27
27
  def partial?
28
28
  config.key?('query')
29
29
  end
30
+
31
+ def has_many
32
+ config.fetch('has_many', [])
33
+ end
30
34
  end
31
35
 
32
36
  def self.instance
@@ -51,10 +55,8 @@ module TableSaw
51
55
  end
52
56
  end
53
57
 
54
- # rubocop:disable Naming/PredicateName
55
- def has_many_mapping
56
- @has_many_mapping ||= config.fetch('has_many', {})
58
+ def has_many
59
+ @has_many ||= config.fetch('has_many', {})
57
60
  end
58
- # rubocop:enable Naming/PredicateName
59
61
  end
60
62
  end
@@ -21,13 +21,11 @@ module TableSaw
21
21
  end
22
22
  end
23
23
 
24
- # rubocop:disable Naming/PredicateName
25
24
  def has_many
26
25
  @has_many ||= result.each_with_object(Hash.new { |h, k| h[k] = [] }) do |row, memo|
27
26
  memo[row['to_table']].push([row['from_table'], row['from_column']])
28
27
  end
29
28
  end
30
- # rubocop:enable Naming/PredicateName
31
29
 
32
30
  private
33
31
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TableSaw
4
- VERSION = '1.0.1'
4
+ VERSION = '1.1.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: table_saw
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamed Asghari
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-11 00:00:00.000000000 Z
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool