partial_ks 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06691f65e761fb70acf6be46198ceb5a9a9a4e6e
4
- data.tar.gz: 955603f6c2ab9d7ab18a43162fc0bd0713ac9f2a
3
+ metadata.gz: 27cf67a4ac72c019e9ce39c13be6949746d319cb
4
+ data.tar.gz: c8aaa05cf43a2c2a3bbc0d5076147ee2593f1d35
5
5
  SHA512:
6
- metadata.gz: 8b8788884ee10d5ba69e64415322fda35bf6420bb98e80e1c7b379ef6afe739fea7d26b7b114b6570c6fb96c854ef222123163d2ed1ddfcbe2366f1a33b03715
7
- data.tar.gz: 48674b2d662fe3aab19c35aec9c25d5ce371e1bfa430bcd08150bf8e5783d96e2fb01df73a66e4d1c459a77687fc4a13c12d8dfda22aceca5aa336f094e8f064
6
+ metadata.gz: 41c5e26c8792bc97720b97aae22da1f4f0ca39014fc7e99b3eb20529557ffeb1dedd2015b164174acca8bf66a683ea0f2cd167b425bff7b04c237ab0c8f55873
7
+ data.tar.gz: 4cbdfbb74cfb845bba856ff2db9bfead21222f42cb61df535404cb3b9b959ad44f8f56880615e9cf7c41770030ca6d15bf221828428e36fffd4b9e59d035bf6d
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ # 0.4.0
4
+
5
+ Allow lambdas to be used as a custom filter
6
+
3
7
  # 0.3.0
4
8
 
5
9
  No functionality changes but specify restrictions already observed in gemspec
data/CONTRIBUTING.md CHANGED
@@ -1,10 +1,25 @@
1
- Tested with activerecord 4.2.7.1, 4.2.8 and 5.0.1 (on Ruby 2.2.3)
1
+ This document should tell all you need to know for contributing to this project.
2
+
3
+ # Testing
4
+
5
+ Tested with activerecord 4.2.7.1, 4.2.8 and 5.0.1 (on Ruby 2.3.3)
2
6
 
3
7
 
4
8
  To install and run tests :
5
9
 
6
10
  ```
7
11
  rm Gemfile.lock
8
- ACTIVERECORD_VERSION="~4.2.8" bundle
12
+ ACTIVERECORD_VERSION="~> 4.2.8" bundle
9
13
  bundle exec rake
10
14
  ```
15
+
16
+ # Design
17
+
18
+ Partial KS is meant to run on *two* databases : the source DB and the target DB.
19
+
20
+ The building of the filter is done on the target DB.
21
+ - Hence, instructions for a table *cannot* be run until all data for its parent
22
+ table is fully downloaded onto the target DB.
23
+
24
+ Filters are run on the source DB.
25
+ - Note that a SQL statement from the target DB will behave differently on the source DB.
data/README.md CHANGED
@@ -20,7 +20,7 @@ You can specify manual configurations if needed.
20
20
 
21
21
  ```
22
22
  manual_configuration = [
23
- [User, nil, User.where(:id => [1])], # specify a subset of users. as users have no parent, specify `nil`
23
+ [User, nil, -> { User.where(:id => [1]) }], # specify a subset of users. as users have no parent, specify `nil`
24
24
  [BlogPost, User] # filter blog_posts by User
25
25
  ]
26
26
  ```
@@ -25,10 +25,12 @@ module PartialKs
25
25
  end
26
26
 
27
27
  def filter_based_on_custom_filter_relation
28
- if custom_filter_relation.is_a?(ActiveRecord::Relation) || custom_filter_relation.respond_to?(:where_sql)
29
- custom_filter_relation.where_sql.to_s.sub(where_regexp, "")
30
- elsif custom_filter_relation.is_a?(String)
31
- custom_filter_relation.sub(where_regexp, "")
28
+ relation = custom_filter_relation.respond_to?(:call) ? custom_filter_relation.call : custom_filter_relation
29
+
30
+ if relation.is_a?(ActiveRecord::Relation) || relation.respond_to?(:where_sql)
31
+ relation.where_sql.to_s.sub(where_regexp, "")
32
+ elsif relation.is_a?(String)
33
+ relation.sub(where_regexp, "")
32
34
  end
33
35
  end
34
36
 
@@ -1,3 +1,3 @@
1
1
  module PartialKs
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -21,6 +21,12 @@ describe "kitchen sync filter" do
21
21
  filtered_table.kitchen_sync_filter.must_equal({"only" => '"post_tags"."id" IN (1, 2)'})
22
22
  end
23
23
 
24
+ it "uses the filter inside a lambda" do
25
+ filter = -> { PostTag.where(:id => [1, 2]) }
26
+ filtered_table = PartialKs::FilteredTable.new(table, nil, custom_filter_relation: filter)
27
+ filtered_table.kitchen_sync_filter.must_equal({"only" => '"post_tags"."id" IN (1, 2)'})
28
+ end
29
+
24
30
  it "uses a SQL where fragment as a filter if provided" do
25
31
  string_filter = "1=0"
26
32
  filtered_table = PartialKs::FilteredTable.new(table, nil, custom_filter_relation: string_filter)
data/test/runner_test.rb CHANGED
@@ -35,7 +35,7 @@ describe 'running based on output from generator' do
35
35
  end
36
36
 
37
37
  it "yields all table names" do
38
- expected_table_names = generator_output.map(&:table_name)
38
+ expected_table_names = [User, Tag, BlogPost].map(&:table_name)
39
39
  actual_table_names = []
40
40
  runner.run! do |tables_to_filter, table_names|
41
41
  actual_table_names += table_names
@@ -45,7 +45,7 @@ describe 'running based on output from generator' do
45
45
  end
46
46
 
47
47
  it "yields all non-null filters" do
48
- expected_filters = generator_output.each_with_object({}) {|ft, hash| hash[ft.table_name] = ft.kitchen_sync_filter if ft.kitchen_sync_filter}
48
+ expected_filters = [User, BlogPost].map(&:table_name)
49
49
  actual_filters = {}
50
50
 
51
51
  runner.run! do |tables_to_filter, table_names|
@@ -53,8 +53,8 @@ describe 'running based on output from generator' do
53
53
  end
54
54
 
55
55
  actual_filters.size.must_equal expected_filters.size
56
- actual_filters.keys.must_equal expected_filters.keys
57
- expected_filters.each do |table_name, filter_condition|
56
+ actual_filters.keys.must_equal expected_filters
57
+ expected_filters.each do |table_name|
58
58
  actual_filters[table_name]["only"].must_be_kind_of String
59
59
  end
60
60
  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.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thong Kuah
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-25 00:00:00.000000000 Z
11
+ date: 2017-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -52,8 +52,9 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: |
56
- A library to use kitchen-sync to sync a subset of your database
55
+ description: 'A library to use kitchen-sync to sync a subset of your database
56
+
57
+ '
57
58
  email: kuahyeow@gmail.com
58
59
  executables: []
59
60
  extensions: []
@@ -104,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
105
  version: '0'
105
106
  requirements: []
106
107
  rubyforge_project:
107
- rubygems_version: 2.4.5.1
108
+ rubygems_version: 2.5.2
108
109
  signing_key:
109
110
  specification_version: 4
110
111
  summary: Partial KS