pgmodelgen 0.4.8 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +132 -0
  3. data/lib/tasks/pgmodelgen.rake +18 -23
  4. metadata +27 -22
  5. data/README.rdoc +0 -19
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ad425f858c9fd2d8c883383358c0a446d775577
4
+ data.tar.gz: 0bd3fa46555b60481a4aa4258ee2f00e4c018235
5
+ SHA512:
6
+ metadata.gz: 4816bf1f58fff79b1effbdb4f6c8b6d4b261e22442c10ad0a29ca55cf333318207a0647109951076fdc5874b89299716c9e9b656bcdde0c5f3f39a848190eb95
7
+ data.tar.gz: 6fd96046ff34ca0a4f7adbee76e9a913bae0d7cce02e2922abe69236f56ac5ffabe897a134f1da35509aadcd16e7b5d60e4ab11c405f7c21cad4414594d310ae
@@ -0,0 +1,132 @@
1
+ # pgmodelgen
2
+
3
+ Rake task that generates/updates activerecord models based on current schema in a postgresql DB.
4
+
5
+ ```
6
+ rake db:gen_model
7
+ ```
8
+
9
+ output
10
+
11
+ ```
12
+ Generating for: my_db.public with prefix
13
+
14
+ Creating models for these tables
15
+
16
+ user
17
+ account
18
+ Writing to ./app/models//user.rb
19
+ Writing to ./app/models//account.rb
20
+
21
+ ```
22
+
23
+ The resulting models
24
+
25
+ ### user.rb
26
+
27
+ ```ruby
28
+ # encoding: utf-8
29
+
30
+ class User < ActiveRecord::Base
31
+
32
+ #--- auto_gen_start ---
33
+ #
34
+ # This is generate using gen_pg_models, dont make changes
35
+ # within auto_gen_XXXXX as it will be overwriten next time
36
+ # gen_pg_models is run.
37
+ #
38
+
39
+ # Columns
40
+
41
+ # email_address text
42
+ # password_hash text
43
+ # user_id int4 nextval('user_user_id_seq'::regclass)
44
+ # account_id int4
45
+
46
+ # Table config
47
+
48
+ self.table_name = "user"
49
+ self.primary_key = "user_id"
50
+ self.sequence_name = "user_user_id_seq"
51
+
52
+ # Constraints
53
+
54
+ validates_presence_of :email_address
55
+ validates_presence_of :password_hash
56
+
57
+
58
+ validates_numericality_of :user_id, :only_integer => true ,:allow_nil => true
59
+ validates_numericality_of :account_id, :only_integer => true
60
+
61
+ validates_uniqueness_of :email_address
62
+
63
+ # Foreign keys
64
+
65
+ belongs_to :fkey____ACCOUNT_account_id____ACCOUNT_account_id____, :foreign_key => :account_id, :primary_key => :account_id, :class_name => "Account"
66
+
67
+ #--- auto_gen_end ---
68
+
69
+ end
70
+ ```
71
+
72
+ ### account.rb
73
+
74
+ ```ruby
75
+ # encoding: utf-8
76
+
77
+ class Account < ActiveRecord::Base
78
+
79
+ #--- auto_gen_start ---
80
+ #
81
+ # This is generate using gen_pg_models, dont make changes
82
+ # within auto_gen_XXXXX as it will be overwriten next time
83
+ # gen_pg_models is run.
84
+ #
85
+
86
+ # Columns
87
+
88
+ # account_id int4 nextval('account_account_id_seq'::regclass)
89
+ # name text
90
+
91
+ # Table config
92
+
93
+ self.table_name = "account"
94
+ self.primary_key = "account_id"
95
+ self.sequence_name = "account_account_id_seq"
96
+
97
+ # Constraints
98
+
99
+ validates_presence_of :name
100
+
101
+
102
+ validates_numericality_of :account_id, :only_integer => true ,:allow_nil => true
103
+
104
+ validates_uniqueness_of :name
105
+
106
+ # Foreign keys
107
+
108
+ has_many :fkey____USER_account_id____ACCOUNT_account_id____, :foreign_key => :account_id, :primary_key => :account_id, :class_name => "User"
109
+
110
+ #--- auto_gen_end ---
111
+
112
+ end
113
+
114
+
115
+
116
+ ```
117
+
118
+
119
+ ## Contributing to pgmodelgen
120
+
121
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
122
+ * Fork the project.
123
+ * _Start a feature/bugfix branch_.
124
+ * Commit and push until you are happy with your contribution.
125
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
126
+ * Please try not to mess with the Rakefile, version, or history.
127
+
128
+ ## Copyright
129
+
130
+ Copyright (c) 2013 Darwin. See LICENSE.txt for
131
+ further details.
132
+
@@ -747,40 +747,35 @@ class PGGen
747
747
 
748
748
  end
749
749
 
750
+ def handle_arguments(args)
751
+ args = args.to_hash
752
+
753
+ if args[:dbname].blank?
754
+ args[:dbname] = ActiveRecord::Base.connection.current_database
755
+ end
756
+
757
+ args[:schema_name] = ActiveRecord::Base.connection.current_schema || 'public' if args[:schema_name].nil? || args[:schema_name].blank?
758
+
759
+ schema_name = args[:schema_name]
760
+ dbname = args[:dbname]
761
+ prefix = (args[:prefix]||'').capitalize
762
+
763
+ return schema_name, dbname, prefix
764
+ end
765
+
750
766
 
751
767
  namespace :db do
752
768
 
753
769
  desc 'Generates/updates activerecord models based on current schema in the postgresql db'
754
770
  task :gen_models => :environment do |t,args|
755
-
756
- args = args.to_hash
757
-
758
- if args[:dbname].blank?
759
- args[:dbname] = ActiveRecord::Base.connection.current_database
760
- end
761
-
762
- args[:schema_name] = 'public' if args[:schema_name].nil? || args[:schema_name].empty?
763
-
764
- schema_name = args[:schema_name]
765
- dbname = args[:dbname]
766
- prefix = (args[:prefix]||'').capitalize
771
+ schema_name, dbname, prefix = handle_arguments(args)
767
772
 
768
773
  PGGen.new(prefix,schema_name,dbname)
769
774
  end
770
775
 
771
776
  desc 'Generates/updates activerecord models based on current schema in the postgresql db for tables matching the supplied regex'
772
777
  task :gen_matching_models,[:regex] => [:environment] do |t,args|
773
- args = args.to_hash
774
-
775
- if args[:dbname].blank?
776
- args[:dbname] = ActiveRecord::Base.connection.current_database
777
- end
778
-
779
- args[:schema_name] = 'public' if args[:schema_name].nil? || args[:schema_name].empty?
780
-
781
- schema_name = args[:schema_name]
782
- dbname = args[:dbname]
783
- prefix = (args[:prefix]||'').capitalize
778
+ schema_name, dbname, prefix = handle_arguments(args)
784
779
 
785
780
  PGGen.new(prefix,schema_name,dbname,args[:regex])
786
781
  end
metadata CHANGED
@@ -1,48 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgmodelgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
5
- prerelease:
4
+ version: 0.4.9
6
5
  platform: ruby
7
6
  authors:
8
7
  - Bjorn Blomqvist
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-05-07 00:00:00.000000000 Z
11
+ date: 2013-10-06 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
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: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: jeweler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
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: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: git
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.5
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.2.5
46
55
  description: Rake task that generates/updates activerecord models based on current
47
56
  schema in the postgresql DB
48
57
  email: darwin@bits2life.com
@@ -50,41 +59,37 @@ executables: []
50
59
  extensions: []
51
60
  extra_rdoc_files:
52
61
  - LICENSE.txt
53
- - README.rdoc
62
+ - README.md
54
63
  files:
55
64
  - lib/metadata_extractor.rb
56
65
  - lib/pgmodelgen.rb
57
66
  - lib/pgmodelgen/railtie.rb
58
67
  - lib/tasks/pgmodelgen.rake
59
68
  - LICENSE.txt
60
- - README.rdoc
69
+ - README.md
61
70
  homepage: http://github.com/bjornblomqvist/pgmodelgen
62
71
  licenses:
63
72
  - MIT
73
+ metadata: {}
64
74
  post_install_message:
65
75
  rdoc_options: []
66
76
  require_paths:
67
77
  - lib
68
78
  required_ruby_version: !ruby/object:Gem::Requirement
69
- none: false
70
79
  requirements:
71
- - - ! '>='
80
+ - - '>='
72
81
  - !ruby/object:Gem::Version
73
82
  version: '0'
74
- segments:
75
- - 0
76
- hash: -1192699231801375479
77
83
  required_rubygems_version: !ruby/object:Gem::Requirement
78
- none: false
79
84
  requirements:
80
- - - ! '>='
85
+ - - '>='
81
86
  - !ruby/object:Gem::Version
82
87
  version: '0'
83
88
  requirements: []
84
89
  rubyforge_project:
85
- rubygems_version: 1.8.24
90
+ rubygems_version: 2.0.6
86
91
  signing_key:
87
- specification_version: 3
92
+ specification_version: 4
88
93
  summary: Rake task that generates/updates activerecord models based on current schema
89
94
  in the postgresql DB
90
95
  test_files: []
@@ -1,19 +0,0 @@
1
- = pgmodelgen
2
-
3
- Rake task that generates/updates activerecord models based on current schema in the postgresql DB.
4
-
5
- == Contributing to pgmodelgen
6
-
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
- * Fork the project.
10
- * Start a feature/bugfix branch.
11
- * Commit and push until you are happy with your contribution.
12
- * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
- * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
-
15
- == Copyright
16
-
17
- Copyright (c) 2013 Darwin. See LICENSE.txt for
18
- further details.
19
-