partial_ks 0.0.5 → 0.0.6

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: 9f64ccee32ef2fecf6953f2916c03e7d13fc061a
4
- data.tar.gz: 2666bf980392217edf9567bee84ebeee87601768
3
+ metadata.gz: 68505ca861cdb0855c62be32cd6b9377f5c6f687
4
+ data.tar.gz: 1dabcb9334a38d27ccbf823237a031aadc4c8b26
5
5
  SHA512:
6
- metadata.gz: 4ac534888ca683de0f4e18d6fd97d9ff245440410dc405a79a126ad4c0ff291f283dfd71128b28b95ec6cc1e9e3cad66fde6ce81d07273731b999f6ad8d8ffe1
7
- data.tar.gz: f10c7800637417c5a7f8c4a6cc76cdf53d2be2ad9536b208e22a96f6cd1e677fce2fd060123b6844ac021d38fa3389e90621178b9224ff0fac92ddc0f0f9fd48
6
+ metadata.gz: fcb48cf2bdcc7151bb99b69a684798185ff6344cc7c7f77fd4316642d0b8ff0eb93f3e00a1f3d41c47f02334473f3b11d9c1a842a32abe976e5cd46e0a6b54e7
7
+ data.tar.gz: 9e50c50f69aab5dff5a040943406d90e35241baa3adf0cef32ea8ce5abbb685a65839d236c9566cddcce5ab86408cb6227402c9bd04c4aa1c8c947c73e39fdc6
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.6
4
+
5
+ Allow manual_configuration to transition to using model names (moving off from table names)
6
+
3
7
  ## 0.0.5
4
8
 
5
9
  API change for `ConfigurationGenerator` - removes `ignored_table_names` option.
@@ -1,59 +1,62 @@
1
1
  # Given an initial table graph
2
2
  # goes through each table not already in the table graph,
3
3
  # and attempts to automatically populate the table into the table graph
4
- class PartialKs::ConfigurationGenerator
5
- attr_reader :table_graph, :table_names
4
+ module PartialKs
5
+ class ConfigurationGenerator
6
+ attr_reader :manual_configuration, :table_names
6
7
 
7
- def initialize(table_graph, table_names: nil)
8
- @table_graph = table_graph
9
- @table_names = table_names || ActiveRecord::Base.connection.tables
10
- end
8
+ def initialize(manual_configuration, table_names: nil)
9
+ @manual_configuration = manual_configuration
10
+ @table_names = table_names || ActiveRecord::Base.connection.tables
11
+ end
11
12
 
12
- def call
13
- @filtered_tables ||= filtered_tables
14
- end
13
+ def call
14
+ @filtered_tables ||= filtered_tables
15
+ end
15
16
 
16
- protected
17
- def all_tables
18
- @all_tables ||= @table_names.map {|table_name| PartialKs::Table.new(table_name) }.select(&:model?).index_by(&:table_name)
19
- end
17
+ protected
18
+ def all_tables
19
+ @all_tables ||= @table_names.map {|table_name| PartialKs::Table.new(table_name) }.select(&:model?).index_by(&:table_name)
20
+ end
20
21
 
21
- def filtered_tables
22
- synced_tables = {}
22
+ def filtered_tables
23
+ synced_tables = {}
23
24
 
24
- table_graph.each do |table_name, specified_parent_model, filter_for_table|
25
- next unless all_tables[table_name]
25
+ manual_configuration.each do |table_name_or_model, specified_parent_model, filter_for_table|
26
+ table_name = table_name_or_model.is_a?(String) ? table_name_or_model : table_name_or_model.table_name
27
+ next unless all_tables[table_name]
26
28
 
27
- parent_model = specified_parent_model
28
- synced_tables[table_name] = PartialKs::FilteredTable.new(all_tables[table_name], parent_model, custom_filter_relation: filter_for_table)
29
- end
29
+ parent_model = specified_parent_model
30
+ synced_tables[table_name] = PartialKs::FilteredTable.new(all_tables[table_name], parent_model, custom_filter_relation: filter_for_table)
31
+ end
32
+
33
+ all_tables.each do |table_name, table|
34
+ next if synced_tables[table_name]
30
35
 
31
- all_tables.each do |table_name, table|
32
- next if synced_tables[table_name]
36
+ begin
37
+ inferrer = PartialKs::ParentInferrer.new(table)
38
+ #TODO get rid of try!
39
+ parent_model = all_tables[inferrer.inferred_parent_table].try!(:model)
40
+ synced_tables[table_name] = PartialKs::FilteredTable.new(table, parent_model)
41
+ rescue PartialKs::ParentInferrer::CannotInfer
42
+ next
43
+ end
33
44
 
34
- begin
35
- inferrer = PartialKs::ParentInferrer.new(table)
36
- #TODO get rid of try!
37
- parent_model = all_tables[inferrer.inferred_parent_table].try!(:model)
38
- synced_tables[table_name] = PartialKs::FilteredTable.new(table, parent_model)
39
- rescue PartialKs::ParentInferrer::CannotInfer
40
- next
41
45
  end
42
46
 
43
- end
47
+ # TODO remove this side effect. Maybe yield or a different method call ?
48
+ puts "***************"
49
+ remaining_size = 0
50
+ all_tables.each do |table_name, table|
51
+ next if synced_tables[table_name]
44
52
 
45
- # TODO remove this side effect. Maybe yield or a different method call ?
46
- puts "***************"
47
- remaining_size = 0
48
- all_tables.each do |table_name, table|
49
- next if synced_tables[table_name]
53
+ puts "#{table.table_name} - #{table.parent_tables.join(',')}"
54
+ remaining_size += 1
55
+ end
56
+ puts "WARNING: #{remaining_size} tables has no configuration"
50
57
 
51
- puts "#{table.table_name} - #{table.parent_tables.join(',')}"
52
- remaining_size += 1
58
+ synced_tables.values
53
59
  end
54
- puts "WARNING: #{remaining_size} tables has no configuration"
55
60
 
56
- synced_tables.values
57
61
  end
58
-
59
62
  end
@@ -1,3 +1,3 @@
1
1
  module PartialKs
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
@@ -32,3 +32,27 @@ describe "generating dependencies" do
32
32
  ]
33
33
  end
34
34
  end
35
+
36
+ describe "transition to model based dependencies" do
37
+ let(:manual_configuration) do
38
+ [
39
+ [User, nil, User.where(:id => [1])],
40
+ ]
41
+ end
42
+
43
+ it "auto infers single belongs-to dependencies" do
44
+ generator(manual_configuration, table_names: pks_tables("users", "blog_posts")).
45
+ must_equal [
46
+ ["users", nil, User.where(:id => [1])],
47
+ ["blog_posts", User, nil]
48
+ ]
49
+ end
50
+
51
+ it "auto infers top level tables" do
52
+ generator(manual_configuration, table_names: pks_tables("users", "tags")).
53
+ must_equal [
54
+ ["users", nil, User.where(:id => [1])],
55
+ ["tags", nil, nil]
56
+ ]
57
+ end
58
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: partial_ks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thong Kuah
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-23 00:00:00.000000000 Z
11
+ date: 2016-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord