partial_ks 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +4 -0
- data/lib/partial_ks/configuration_generator.rb +43 -40
- data/lib/partial_ks/version.rb +1 -1
- data/test/configuration_generator_test.rb +24 -0
- 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: 68505ca861cdb0855c62be32cd6b9377f5c6f687
|
4
|
+
data.tar.gz: 1dabcb9334a38d27ccbf823237a031aadc4c8b26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcb48cf2bdcc7151bb99b69a684798185ff6344cc7c7f77fd4316642d0b8ff0eb93f3e00a1f3d41c47f02334473f3b11d9c1a842a32abe976e5cd46e0a6b54e7
|
7
|
+
data.tar.gz: 9e50c50f69aab5dff5a040943406d90e35241baa3adf0cef32ea8ce5abbb685a65839d236c9566cddcce5ab86408cb6227402c9bd04c4aa1c8c947c73e39fdc6
|
data/CHANGES.md
CHANGED
@@ -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
|
-
|
5
|
-
|
4
|
+
module PartialKs
|
5
|
+
class ConfigurationGenerator
|
6
|
+
attr_reader :manual_configuration, :table_names
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
13
|
+
def call
|
14
|
+
@filtered_tables ||= filtered_tables
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
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
|
-
|
22
|
-
|
22
|
+
def filtered_tables
|
23
|
+
synced_tables = {}
|
23
24
|
|
24
|
-
|
25
|
-
|
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
|
-
|
28
|
-
|
29
|
-
|
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
|
-
|
32
|
-
|
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
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
-
|
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
|
data/lib/partial_ks/version.rb
CHANGED
@@ -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.
|
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
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|