pg_closure_tree_rebuild 0.1.0 → 1.0.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: c64dc28a4a9b38273e37a80b71159be54beae34d
4
- data.tar.gz: 487daa0b155d4bc97d6f801a6244910b7fb87618
3
+ metadata.gz: ad6d8c266153123f106dcc223c3e5c588076f78b
4
+ data.tar.gz: a88791a4e3374895146aeaaded5945c2f9509bd0
5
5
  SHA512:
6
- metadata.gz: a21ad70e898627c19b5e5bd9e5d37a989c39c1cfb8795feb729fc90a78107a5986e856195b5b80890e5e5e11efd5ff7ba8c5bf7910aa1979f475deca32385d2a
7
- data.tar.gz: a51a1d60ea86e451a1aa7d790677ffdb9ba2d715c8627eb321beef68ab489f49b0073b0a57d68698e40c8f3b27e0cac0311eda5f6ef356b532c9ebbd1e77293e
6
+ metadata.gz: 5be88e56ff568468c3e493f5df5f352a8ee8d5bee66099465df2d01053a44826c275897513a988f9ed2338b5dfb21a75e7de1820aff34572bb9f0056d3ba6e4a
7
+ data.tar.gz: 6bb4e48b8f12a7cda3e263a042c45b20e3476777a718638c94557ad10ce1266df10114070857df712c05e3c86b32cc951ea74ffed41bbd86e277abfe36eb047a
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1
4
- - jruby-19mode
3
+ - 2.2
5
4
  cache: bundler
6
5
  sudo: false
7
6
 
@@ -1,5 +1,10 @@
1
+ require 'ruby-progressbar'
2
+ require 'sequel'
3
+ require 'active_support/core_ext/string/inflections'
4
+
1
5
  require 'pg_closure_tree_rebuild/version'
2
6
  require 'pg_closure_tree_rebuild/builder'
7
+ require 'pg_closure_tree_rebuild/runner'
3
8
  require 'pg_closure_tree_rebuild/railtie' if defined?(Rails)
4
9
 
5
10
  module PgClosureTreeRebuild
@@ -0,0 +1,31 @@
1
+ module PgClosureTreeRebuild
2
+ class Runner
3
+ def initialize(db, table, hierarchies = nil, parent_id = 'parent_id', id = 'id')
4
+ @db = db
5
+
6
+ hierarchies ||= "#{table.singularize}_hierarchies"
7
+ parent_id ||= 'parent_id'
8
+ id ||= 'id'
9
+
10
+ @scope = db[table.to_sym]
11
+ hierarchies = hierarchies.to_sym
12
+
13
+ @builder = PgClosureTreeRebuild::Builder.new(
14
+ @scope,
15
+ hierarchies.to_sym,
16
+ id: id.to_sym,
17
+ parent_id: parent_id.to_sym
18
+ )
19
+ end
20
+
21
+ def run
22
+ puts 'Calculating chains...'
23
+ bar = ProgressBar.create(total: @builder.chains.size)
24
+
25
+ puts "Records: #{@scope.count}"
26
+
27
+ puts 'Importing...'
28
+ @builder.rebuild(@db) { bar.increment }
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module PgClosureTreeRebuild
2
- VERSION = '0.1.0'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,37 +1,15 @@
1
1
  require 'pg_closure_tree_rebuild'
2
- require 'ruby-progressbar'
3
- require 'sequel'
4
- require 'active_support/core_ext/string/inflections'
5
2
  require 'benchmark'
6
3
 
7
4
  namespace :closure_tree do
8
5
  desc 'Rebuild hierarchy (TABLE, HIERARCHIES, DATABASE_URL, PARENT_ID, ID)'
9
6
  task :rebuild do
10
7
  puts Benchmark.measure {
11
- DB = Sequel.connect(ENV['DATABASE_URL'])
8
+ db = Sequel.connect(ENV['DATABASE_URL'])
12
9
 
13
- table = ENV['TABLE']
14
- hierarchies = ENV['HIERARCHIES'] || "#{table.singularize}_hierarchies"
15
- parent_id = ENV['PARENT_ID'] || 'parent_id'
16
- id = ENV['ID'] || 'id'
17
-
18
- scope = DB[table.to_sym]
19
- hierarchies = hierarchies.to_sym
20
-
21
- builder = PgClosureTreeRebuild::Builder.new(
22
- scope,
23
- hierarchies.to_sym,
24
- id: id.to_sym,
25
- parent_id: parent_id.to_sym
26
- )
27
-
28
- puts 'Calculating chains...'
29
- bar = ProgressBar.create(total: builder.chains.size)
30
-
31
- puts "Records: #{scope.count}"
32
-
33
- puts 'Importing...'
34
- builder.rebuild(DB) { bar.increment }
10
+ PgClosureTreeRebuild::Runner.new(
11
+ db, ENV['TABLE'], ENV['HIERARCHIES'], ENV['PARENT_ID'], ENV['ID']
12
+ ).run
35
13
  }
36
14
  end
37
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_closure_tree_rebuild
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor Sokolov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-12 00:00:00.000000000 Z
11
+ date: 2015-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sequel
@@ -185,6 +185,7 @@ files:
185
185
  - lib/pg_closure_tree_rebuild.rb
186
186
  - lib/pg_closure_tree_rebuild/builder.rb
187
187
  - lib/pg_closure_tree_rebuild/railtie.rb
188
+ - lib/pg_closure_tree_rebuild/runner.rb
188
189
  - lib/pg_closure_tree_rebuild/version.rb
189
190
  - pg_closure_tree_rebuild.gemspec
190
191
  - tasks/closure_tree.rake
@@ -208,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
209
  version: '0'
209
210
  requirements: []
210
211
  rubyforge_project:
211
- rubygems_version: 2.2.2
212
+ rubygems_version: 2.4.8
212
213
  signing_key:
213
214
  specification_version: 4
214
215
  summary: 'Quick #rebuild! method implementation for closure_tree on PostgreSQL.'