pg_examiner 0.4.0 → 0.4.1

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: 5643afd2534a1e85ecb2508240f121250c781287
4
- data.tar.gz: cc9c1a56805634ea8d72b0ab2225b3d48fae0c21
3
+ metadata.gz: 36c51dbbc8e2fccfd5eee408216749e98c20086d
4
+ data.tar.gz: 373bfeb979ed1012d4a05daf1dd5d4720b8c8a65
5
5
  SHA512:
6
- metadata.gz: 8b7898f913fef164ab2b0394efb15890a3bfcd3bd2c7f56cdc588a7ae1e8b18445c90eb0d548ea71c95b410b4b0041435bd864ca53b59a81d294c12d06658884
7
- data.tar.gz: 651a2956ad12e1355875dee49a59cbaa75076ce6f087ff11fddcb316f74a753bdf9bfc35075fba7e8a9017069b763298dc2e8c329b2f3371ff0f92c69ea306f2
6
+ metadata.gz: 982b849a8951bf7f9b783cf6ccb9e29d78d55c52a8d0158ec0f15dd474a1986a43a2b88931e0aff1a80915cb7683d82fd1e71b09c192374bb38c8a4650d5aa9c
7
+ data.tar.gz: 79cb8766ad4867ea4170dc6e5445ed86f849bba61e900982800a4a4355aa600fae7779f7c7176190fa3481375b649db028d4a175b1b79eb81cd466cbdb3dba0b
@@ -3,11 +3,12 @@
3
3
  module PGExaminer
4
4
  class Result
5
5
  class Function < Item
6
+ EXCESS_WHITESPACE_REGEX = /\s+/.freeze
7
+
6
8
  def diffable_attrs
7
9
  {
8
10
  "name" => "name",
9
11
  "proargmodes" => "argument modes",
10
- "definition" => "function definition",
11
12
  }
12
13
  end
13
14
 
@@ -16,9 +17,16 @@ module PGExaminer
16
17
  "argument_types" => "argument types",
17
18
  "return_type" => "return type",
18
19
  "language" => "language",
20
+ "definition" => "function definition",
19
21
  }
20
22
  end
21
23
 
24
+ def definition
25
+ s = @row['definition'].strip
26
+ s.gsub!(EXCESS_WHITESPACE_REGEX, ' ')
27
+ s
28
+ end
29
+
22
30
  def argument_types
23
31
  @argument_types ||= @row['proargtypes'].split.map do |oid|
24
32
  result.pg_type.find{|t| t['oid'] == oid}['name']
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PGExaminer
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
  end
@@ -76,8 +76,8 @@ describe PGExaminer do
76
76
  b.should_not == d
77
77
  c.should_not == d
78
78
 
79
- a.diff(b).should == {"schemas"=>{"public"=>{"functions"=>{"add"=>{"function definition"=>{"CREATE OR REPLACE FUNCTION public.add(one integer, two integer)\n RETURNS integer\n LANGUAGE sql\nAS $function$\n SELECT one + two\n $function$\n"=>"CREATE OR REPLACE FUNCTION public.add(one integer, two integer, three integer)\n RETURNS integer\n LANGUAGE sql\nAS $function$\n SELECT one + two\n $function$\n"}, "argument types"=>{["int4", "int4"]=>["int4", "int4", "int4"]}}}}}}
80
- a.diff(c).should == {"schemas"=>{"public"=>{"functions"=>{"add"=>{"function definition"=>{"CREATE OR REPLACE FUNCTION public.add(one integer, two integer)\n RETURNS integer\n LANGUAGE sql\nAS $function$\n SELECT one + two\n $function$\n"=>"CREATE OR REPLACE FUNCTION public.add(one integer, two integer, three integer[])\n RETURNS integer\n LANGUAGE sql\nAS $function$\n SELECT one + two\n $function$\n"}, "argument types"=>{["int4", "int4"]=>["int4", "int4", "_int4"]}}}}}}
79
+ a.diff(b).should == {"schemas"=>{"public"=>{"functions"=>{"add"=>{"function definition"=>{"CREATE OR REPLACE FUNCTION public.add(one integer, two integer) RETURNS integer LANGUAGE sql AS $function$ SELECT one + two $function$"=>"CREATE OR REPLACE FUNCTION public.add(one integer, two integer, three integer) RETURNS integer LANGUAGE sql AS $function$ SELECT one + two $function$"}, "argument types"=>{["int4", "int4"]=>["int4", "int4", "int4"]}}}}}}
80
+ a.diff(c).should == {"schemas"=>{"public"=>{"functions"=>{"add"=>{"function definition"=>{"CREATE OR REPLACE FUNCTION public.add(one integer, two integer) RETURNS integer LANGUAGE sql AS $function$ SELECT one + two $function$"=>"CREATE OR REPLACE FUNCTION public.add(one integer, two integer, three integer[]) RETURNS integer LANGUAGE sql AS $function$ SELECT one + two $function$"}, "argument types"=>{["int4", "int4"]=>["int4", "int4", "_int4"]}}}}}}
81
81
  end
82
82
 
83
83
  it "should be able to differentiate between functions by their argument defaults" do
@@ -255,4 +255,44 @@ describe PGExaminer do
255
255
  a.should_not == c
256
256
  a.should_not == d
257
257
  end
258
+
259
+ it "should ignore whitespace in function definitions" do
260
+ a = examine <<-SQL_FUNCTION
261
+ CREATE FUNCTION add(one integer, two integer) RETURNS integer
262
+ AS $$
263
+ SELECT one + two
264
+ $$
265
+ LANGUAGE SQL;
266
+ SQL_FUNCTION
267
+
268
+ b = examine <<-SQL_FUNCTION
269
+ CREATE FUNCTION add(one integer, two integer) RETURNS integer
270
+ AS $$
271
+ SELECT one + two
272
+ $$
273
+ LANGUAGE SQL;
274
+ SQL_FUNCTION
275
+
276
+ c = examine <<-SQL_FUNCTION
277
+ CREATE FUNCTION add(one integer, two integer) RETURNS integer
278
+ AS $$
279
+ SELECT one + two
280
+ $$
281
+ LANGUAGE SQL;
282
+ SQL_FUNCTION
283
+
284
+ d = examine <<-SQL_FUNCTION
285
+ CREATE FUNCTION add(one integer, two integer) RETURNS integer
286
+ AS $$
287
+ SELECT one + two
288
+
289
+
290
+ $$
291
+ LANGUAGE SQL;
292
+ SQL_FUNCTION
293
+
294
+ a.should == b
295
+ a.should == c
296
+ a.should == d
297
+ end
258
298
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_examiner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hanks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-08 00:00:00.000000000 Z
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg