hairtrigger 0.2.14 → 0.2.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 626460677ceaa19be59baad0532d142bb45ba072
4
+ data.tar.gz: d2beebf4d2531400d04fa6ed545bebb2f849598a
5
+ SHA512:
6
+ metadata.gz: c3b9cfbee129c14b01d6cfa4d00b3e9ac8ea9a2fe9f20dcc1199c38e7ef8b7f92cbe2e0dd9148c0975f273b8870c80c25de28181754e888118cfd593a0617d86
7
+ data.tar.gz: 9213b2f59bae5879c013db5194105cbffd93e2cebcdb77f0089a2cda69a09d965da320d08f3457dc1debae8107ab958e9928726d3345f3f22d1c4f355102cd86
@@ -403,7 +403,7 @@ module HairTrigger
403
403
  when :sqlite, :mysql
404
404
  "DROP TRIGGER IF EXISTS #{prepared_name};\n"
405
405
  when :postgresql, :postgis
406
- "DROP TRIGGER IF EXISTS #{prepared_name} ON #{options[:table]};\nDROP FUNCTION IF EXISTS #{prepared_name}();\n"
406
+ "DROP TRIGGER IF EXISTS #{prepared_name} ON #{adapter.quote_table_name(options[:table])};\nDROP FUNCTION IF EXISTS #{adapter.quote_table_name(prepared_name)}();\n"
407
407
  else
408
408
  raise GenerationError, "don't know how to drop #{adapter_name} triggers yet"
409
409
  end
@@ -434,7 +434,7 @@ END;
434
434
  else
435
435
  security = options[:security] if options[:security] && options[:security] != :invoker
436
436
  sql << <<-SQL
437
- CREATE FUNCTION #{prepared_name}()
437
+ CREATE FUNCTION #{adapter.quote_table_name(prepared_name)}()
438
438
  RETURNS TRIGGER AS $$#{declarations}
439
439
  BEGIN
440
440
  SQL
@@ -460,11 +460,11 @@ END;
460
460
  $$ LANGUAGE plpgsql#{security ? " SECURITY #{security.to_s.upcase}" : ""};
461
461
  SQL
462
462
 
463
- trigger_action = "#{prepared_name}()"
463
+ trigger_action = "#{adapter.quote_table_name(prepared_name)}()"
464
464
  end
465
465
 
466
466
  [sql, <<-SQL]
467
- CREATE TRIGGER #{prepared_name} #{options[:timing]} #{options[:events].join(" OR ")} #{of_clause}ON "#{options[:table]}"
467
+ CREATE TRIGGER #{prepared_name} #{options[:timing]} #{options[:events].join(" OR ")} #{of_clause}ON #{adapter.quote_table_name(options[:table])}
468
468
  FOR EACH #{options[:for_each]}#{prepared_where && db_version >= 90000 ? " WHEN (" + prepared_where + ')': ''} EXECUTE PROCEDURE #{trigger_action};
469
469
  SQL
470
470
  end
@@ -23,7 +23,11 @@ module HairTrigger
23
23
  definitions = []
24
24
  builder.generate.each do |statement|
25
25
  if statement =~ /\ACREATE(.*TRIGGER| FUNCTION) ([^ \n]+)/
26
- definitions << [$2, statement, $1 == ' FUNCTION' ? :function : :trigger]
26
+ # poor man's unquote
27
+ type = ($1 == ' FUNCTION' ? :function : :trigger)
28
+ name = $2.gsub('"', '')
29
+
30
+ definitions << [name, statement, type]
27
31
  end
28
32
  end
29
33
  {:builder => builder, :definitions => definitions}
@@ -63,23 +67,24 @@ module HairTrigger
63
67
  @adapter_name = @connection.adapter_name.downcase.to_sym
64
68
 
65
69
  return definition unless @adapter_name == :postgresql
66
- begin
67
- # because postgres does not preserve the original CREATE TRIGGER/
68
- # FUNCTION statements, its decompiled reconstruction will not match
69
- # ours. we work around it by creating our generated trigger/function,
70
- # asking postgres for its definition, and then rolling back.
71
- begin
72
- @connection.transaction do
73
- chars = ('a'..'z').to_a + ('0'..'9').to_a + ['_']
74
- test_name = '_hair_trigger_test_' + (0..43).map{ chars[(rand * chars.size).to_i] }.join
75
- test_name << (type == :function ? '()' : '')
76
- @connection.execute(definition.sub(name, test_name))
77
- definition = @connection.triggers(:only => [test_name], :simple_check => true).values.first
78
- definition.sub!(test_name, name)
79
- raise
80
- end
81
- rescue
70
+ # because postgres does not preserve the original CREATE TRIGGER/
71
+ # FUNCTION statements, its decompiled reconstruction will not match
72
+ # ours. we work around it by creating our generated trigger/function,
73
+ # asking postgres for its definition, and then rolling back.
74
+ @connection.transaction(requires_new: true) do
75
+ chars = ('a'..'z').to_a + ('0'..'9').to_a + ['_']
76
+ test_name = '_hair_trigger_test_' + (0..43).map{ chars[(rand * chars.size).to_i] }.join
77
+ # take of the parens for gsubbing, since this version might be quoted
78
+ name = name[0..-3] if type == :function
79
+ @connection.execute(definition.sub(name, test_name))
80
+ # now add them back
81
+ if type == :function
82
+ test_name << '()'
83
+ name << '()'
82
84
  end
85
+ definition = @connection.triggers(:only => [test_name], :simple_check => true).values.first
86
+ definition.sub!(test_name, name)
87
+ raise ActiveRecord::Rollback
83
88
  end
84
89
  definition
85
90
  end
@@ -1,5 +1,5 @@
1
1
  module HairTrigger
2
- VERSION = "0.2.14"
2
+ VERSION = "0.2.15"
3
3
 
4
4
  def VERSION.<=>(other)
5
5
  split(/\./).map(&:to_i) <=> other.split(/\./).map(&:to_i)
@@ -10,6 +10,10 @@ class MockAdapter
10
10
  instance_eval("def #{key}; #{value.inspect}; end")
11
11
  end
12
12
  end
13
+
14
+ def quote_table_name(table)
15
+ table
16
+ end
13
17
  end
14
18
 
15
19
  def builder(name = nil)
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hairtrigger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.14
5
- prerelease:
4
+ version: 0.2.15
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jon Jensen
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-05-07 00:00:00.000000000 Z
11
+ date: 2015-10-21 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '2.3'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '2.3'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: ruby_parser
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ~>
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '3.5'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ~>
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '3.5'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: ruby2ruby
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ~>
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '2.0'
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ~>
52
+ - - "~>"
60
53
  - !ruby/object:Gem::Version
61
54
  version: '2.0'
62
55
  description: allows you to declare database triggers in ruby in your models, and then
@@ -67,8 +60,9 @@ extensions: []
67
60
  extra_rdoc_files: []
68
61
  files:
69
62
  - LICENSE.txt
70
- - Rakefile
71
63
  - README.md
64
+ - Rakefile
65
+ - lib/hair_trigger.rb
72
66
  - lib/hair_trigger/adapter.rb
73
67
  - lib/hair_trigger/base.rb
74
68
  - lib/hair_trigger/builder.rb
@@ -77,17 +71,16 @@ files:
77
71
  - lib/hair_trigger/railtie.rb
78
72
  - lib/hair_trigger/schema_dumper.rb
79
73
  - lib/hair_trigger/version.rb
80
- - lib/hair_trigger.rb
81
74
  - lib/hairtrigger.rb
82
75
  - lib/tasks/hair_trigger.rake
83
76
  - spec/adapter_spec.rb
84
77
  - spec/builder_spec.rb
85
- - spec/migrations/20110331212003_initial_tables.rb
86
- - spec/migrations/20110331212631_user_trigger.rb
87
- - spec/migrations/20110417185102_manual_user_trigger.rb
88
78
  - spec/migrations-pre-3.1/20110331212003_initial_tables.rb
89
79
  - spec/migrations-pre-3.1/20110331212631_user_trigger.rb
90
80
  - spec/migrations-pre-3.1/20110417185102_manual_user_trigger.rb
81
+ - spec/migrations/20110331212003_initial_tables.rb
82
+ - spec/migrations/20110331212631_user_trigger.rb
83
+ - spec/migrations/20110417185102_manual_user_trigger.rb
91
84
  - spec/migrations_spec.rb
92
85
  - spec/models/group.rb
93
86
  - spec/models/user.rb
@@ -96,27 +89,26 @@ files:
96
89
  homepage: http://github.com/jenseng/hair_trigger
97
90
  licenses:
98
91
  - MIT
92
+ metadata: {}
99
93
  post_install_message:
100
94
  rdoc_options: []
101
95
  require_paths:
102
96
  - lib
103
97
  required_ruby_version: !ruby/object:Gem::Requirement
104
- none: false
105
98
  requirements:
106
- - - ! '>='
99
+ - - ">="
107
100
  - !ruby/object:Gem::Version
108
101
  version: 1.8.7
109
102
  required_rubygems_version: !ruby/object:Gem::Requirement
110
- none: false
111
103
  requirements:
112
- - - ! '>='
104
+ - - ">="
113
105
  - !ruby/object:Gem::Version
114
106
  version: 1.3.5
115
107
  requirements: []
116
108
  rubyforge_project:
117
- rubygems_version: 1.8.23.2
109
+ rubygems_version: 2.2.2
118
110
  signing_key:
119
- specification_version: 3
111
+ specification_version: 4
120
112
  summary: easy database triggers for active record
121
113
  test_files: []
122
114
  has_rdoc: