pgmodelgen 0.5.3 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tasks/pgmodelgen.rake +29 -10
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb4be41191539822879579ae93250a5013886577
4
- data.tar.gz: 1276ce97601747801a990e69845b879d0cf7cf47
3
+ metadata.gz: 9660cf2dc65c39c1b5fad728e5c0fea953e90d4d
4
+ data.tar.gz: 6be5c386fd6f49f88353888e13d6251cbfeddda6
5
5
  SHA512:
6
- metadata.gz: 5b06ef51aebdc70d06432bbb70d2d36eea17480a88e8ef5ec38887caf18c1f7e98b7a08769e191a46f056b624bb2c6cbd0424333fc7fc60ffcf52bddbc957fea
7
- data.tar.gz: 3781de626266a243ef62a0e62e196af4093c6b25624ac40057b4f507d3c58e28a0da803e4ce496753736eaee90901ba6876bcbb0ca732651724e12eaa2819b26
6
+ metadata.gz: 4a109b7bf4fa56c82484c4a3d48fd5464f5d6bf5eb8066991e7fb50117655c9faa961d6fc59f43e8c924b0140cc1547403fcedbc8387714301061ca3fd8bc987
7
+ data.tar.gz: 61d7d5fb0538cdce1039e6bfa29d5ec7b3b0c5f2ea1cfde06d04268b0e39e2eb91eb16949f42842b4b33c5e472558aaf1c2434c54a028347fe586c4bfd97a605
@@ -12,6 +12,7 @@
12
12
  # TODO Update so that a unique constraint on a foreign key changes the has_many to has_one
13
13
  # TODO Add hint where a foregin key is to a many to many table
14
14
 
15
+ # DONE Add interval syntax validation (Added basic validation. Can only handle HH:MM:SS)
15
16
  # DONE Add warning about missing index on foreign keys
16
17
  # DONE Fix foreign_key mistake
17
18
  # DONE Make the result a bit nicer
@@ -599,14 +600,26 @@ class PGGen
599
600
 
600
601
  # Regex check constraint
601
602
  match = row['condition_decleration_src'].match('\)::text ~\* \'(.*)\'::text\)$')
602
- regex_ruby_style = match[1].gsub('\\\\.','').gsub('/','\/').gsub(/^\^/,"\\A").gsub(/\$$/,"\\z")
603
+ regex_ruby_style = match[1].gsub(/^\^/,"\\A").gsub(/\$$/,"\\z").gsub('\\\\','\\')
603
604
  models[table_name][:constraint] += "\tvalidates_format_of :#{column_rows.first["attribute_name"]}, :with => /#{regex_ruby_style}/i#{allow_nil}\n"
604
-
605
+ elsif row['condition_decleration_src'].match('\)::text ~ \'(.*)\'::text\)$')
606
+
607
+ # Case senstaive regex check constraint
608
+ match = row['condition_decleration_src'].match('\)::text ~ \'(.*)\'::text\)$')
609
+ regex_ruby_style = match[1].gsub(/^\^/,"\\A").gsub(/\$$/,"\\z").gsub('\\\\','\\')
610
+ models[table_name][:constraint] += "\tvalidates_format_of :#{column_rows.first["attribute_name"]}, :with => /#{regex_ruby_style}/#{allow_nil}\n"
611
+
605
612
  elsif row['condition_decleration_src'].match(/\(char_length\((.*)::text\) >= ([0-9]*)\)/)
606
613
 
607
614
  # Length constraint
608
615
  match = row['condition_decleration_src'].match(/^\(char_length\(\((.*)\)::text\) >= ([0-9]*)\)$/)
609
616
  models[table_name][:constraint] += "\tvalidates_length_of :#{match[1]}, :minimum => #{match[2]}\n"
617
+
618
+ elsif row['condition_decleration_src'].match(/^\((.*) > ([0-9]*)\)$/)
619
+
620
+ # Number constraint
621
+ match = row['condition_decleration_src'].match(/^\((.*) > ([0-9]*)\)$/)
622
+ models[table_name][:constraint] += "\tvalidates_numericality_of :#{match[1]}, :greater_than => #{match[2]}\n"
610
623
 
611
624
  else
612
625
 
@@ -678,7 +691,7 @@ class PGGen
678
691
  pg_attribute.attrelid = #{oid}
679
692
  and pg_attribute.attnum > 0
680
693
 
681
- order by attribute_name;
694
+ order by attribute_number;
682
695
  "
683
696
 
684
697
  columns_buffer = ""
@@ -733,15 +746,21 @@ class PGGen
733
746
  #
734
747
  models[table_name][:constraint] += "\n"
735
748
  result.each do |row|
736
- if row['type_name'].include? "int"
737
- allow_nil = ((row['not_null_constraint'] != 't' or row['has_default_value'] == 't') ? ",:allow_nil => true" : "")
738
- models[table_name][:constraint] += "\tvalidates_numericality_of :#{row['attribute_name']}, :only_integer => true #{allow_nil} \n"
739
- end
749
+ column_name = row['attribute_name']
750
+ allow_nil = ((row['not_null_constraint'] != 't' or row['has_default_value'] == 't') ? ",:allow_nil => true" : "")
740
751
 
741
- if row['type_name'].include? "float"
742
- allow_nil = ((row['not_null_constraint'] != 't' or row['has_default_value'] == 't') ? ",:allow_nil => true" : "")
743
- models[table_name][:constraint] += "\tvalidates_numericality_of :#{row['attribute_name']} #{allow_nil} \n"
752
+ constraint = case row['type_name']
753
+ when /^(int2|int4|int8)$/
754
+ "validates_numericality_of :#{column_name}, :only_integer => true"
755
+ when /^(float4|float8)$/
756
+ "validates_numericality_of :#{column_name}"
757
+ when /^interval$/
758
+ "validates_format_of :#{column_name}, :with => /\\A(\\d+:\\d{1,2}(:\\d{1,2}|)|\\d+)\\z/"
759
+ else
760
+ nil
744
761
  end
762
+
763
+ models[table_name][:constraint] += "\t#{constraint} #{allow_nil} \n" if constraint
745
764
  end
746
765
 
747
766
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgmodelgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bjorn Blomqvist
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-17 00:00:00.000000000 Z
11
+ date: 2014-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -61,12 +61,12 @@ extra_rdoc_files:
61
61
  - LICENSE.txt
62
62
  - README.md
63
63
  files:
64
+ - LICENSE.txt
65
+ - README.md
64
66
  - lib/metadata_extractor.rb
65
67
  - lib/pgmodelgen.rb
66
68
  - lib/pgmodelgen/railtie.rb
67
69
  - lib/tasks/pgmodelgen.rake
68
- - LICENSE.txt
69
- - README.md
70
70
  homepage: http://github.com/bjornblomqvist/pgmodelgen
71
71
  licenses:
72
72
  - LGPL
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  version: '0'
88
88
  requirements: []
89
89
  rubyforge_project:
90
- rubygems_version: 2.0.6
90
+ rubygems_version: 2.2.2
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: Rake task that generates/updates activerecord models based on current schema