Skip to content

Commit 9a3e028

Browse files
author
Keith Gabryelski
committed
changes for after create hooks
1 parent fd5cc04 commit 9a3e028

File tree

8 files changed

+29
-10
lines changed

8 files changed

+29
-10
lines changed

Gemfile.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
partitioned (1.1.3)
4+
partitioned (1.1.4)
55
bulk_data_methods (= 1.0.0)
66
pg
77
rails (>= 3.2.8)
@@ -48,22 +48,22 @@ GEM
4848
hike (1.2.1)
4949
i18n (0.6.1)
5050
journey (1.0.4)
51-
jquery-rails (2.1.4)
51+
jquery-rails (2.2.0)
5252
railties (>= 3.0, < 5.0)
5353
thor (>= 0.14, < 2.0)
5454
json (1.7.6)
5555
mail (2.4.4)
5656
i18n (>= 0.4.0)
5757
mime-types (~> 1.16)
5858
treetop (~> 1.4.8)
59-
mime-types (1.19)
59+
mime-types (1.20.1)
6060
multi_json (1.5.0)
6161
pg (0.14.1)
6262
polyglot (0.3.3)
6363
rack (1.4.4)
6464
rack-cache (1.2)
6565
rack (>= 0.4)
66-
rack-ssl (1.3.2)
66+
rack-ssl (1.3.3)
6767
rack
6868
rack-test (0.6.2)
6969
rack (>= 1.0)
@@ -88,7 +88,7 @@ GEM
8888
rspec-core (2.12.2)
8989
rspec-expectations (2.12.1)
9090
diff-lcs (~> 1.1.3)
91-
rspec-mocks (2.12.1)
91+
rspec-mocks (2.12.2)
9292
rspec-rails (2.12.2)
9393
actionpack (>= 3.0)
9494
activesupport (>= 3.0)
@@ -101,7 +101,7 @@ GEM
101101
multi_json (~> 1.0)
102102
rack (~> 1.0)
103103
tilt (~> 1.1, != 1.3.0)
104-
thor (0.16.0)
104+
thor (0.17.0)
105105
tilt (1.3.3)
106106
treetop (1.4.12)
107107
polyglot

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2010-2012, Fiksu, Inc.
1+
Copyright (c) 2010-2013, Fiksu, Inc.
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without

lib/partitioned/partitioned_base/configurator/data.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def self.foreign_key_to_foreign_table_name(foreign_key_field)
4242
:schema_name, :name_prefix, :base_name,
4343
:part_name, :table_name, :table_alias_name, :parent_table_schema_name,
4444
:parent_table_name, :check_constraint, :encoded_name,
45-
:janitorial_creates_needed, :janitorial_archives_needed, :janitorial_drops_needed
45+
:janitorial_creates_needed, :janitorial_archives_needed, :janitorial_drops_needed,
46+
:after_partition_table_create_hooks
4647

4748
def initialize
4849
@on_field = nil
@@ -70,6 +71,8 @@ def initialize
7071
@janitorial_creates_needed = nil
7172
@janitorial_archives_needed = nil
7273
@janitorial_drops_needed = nil
74+
75+
@after_partition_table_create_hooks = []
7376
end
7477
end
7578
end

lib/partitioned/partitioned_base/configurator/dsl.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ def foreign_key(referencing_field, referenced_table = nil, referenced_field = :i
263263
end
264264
end
265265

266+
def after_partition_table_create_hook(method_name)
267+
if method_name.is_a? Proc
268+
data.after_partition_table_create_hooks << method_name
269+
else
270+
# XXX should be a symbol
271+
data.after_partition_table_create_hooks << lambda {|model,*partition_key_values| model.send(method_name, *partition_key_values)}
272+
end
273+
end
274+
275+
266276
#
267277
# Define the check constraint for a given child table.
268278
#

lib/partitioned/partitioned_base/configurator/reader.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def initialize(most_derived_activerecord_class)
3030
@janitorial_creates_needed = nil
3131
@janitorial_archives_needed = nil
3232
@janitorial_drops_needed = nil
33+
@after_partition_table_create_hooks = nil
3334
end
3435

3536
#
@@ -167,6 +168,10 @@ def janitorial_drops_needed
167168
return @janitorial_drops_needed
168169
end
169170

171+
def run_after_partition_table_create_hooks(*partition_key_values)
172+
collect_from_collection(*partition_key_values, &:after_partition_table_create_hooks)
173+
end
174+
170175
protected
171176

172177
def configurators

lib/partitioned/partitioned_base/partition_manager.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def create_new_partition(*partition_key_values)
127127
create_partition_table(*partition_key_values)
128128
add_partition_table_index(*partition_key_values)
129129
add_references_to_partition_table(*partition_key_values)
130+
configurator.run_after_partition_table_create_hooks(*partition_key_values)
130131
end
131132

132133
##

lib/partitioned/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module Partitioned
22
# the current version of this gem
3-
VERSION = "1.1.3"
3+
VERSION = "1.1.4"
44
end

partitioned.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
77
s.name = 'partitioned'
88
s.version = Partitioned::VERSION
99
s.license = 'New BSD License'
10-
s.date = '2013-10-14'
10+
s.date = '2013-02-04'
1111
s.summary = "Postgres table partitioning support for ActiveRecord."
1212
s.description = "A gem providing support for table partitioning in ActiveRecord. Support is only available for postgres databases. Other features include child table management (creation and deletion) and bulk data creating and updating."
1313
s.authors = ["Keith Gabryelski", "Aleksandr Dembskiy"]

0 commit comments

Comments
 (0)