model_mill 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # Model Mill #
2
+
3
+ ## 0.3.0 / 2011-01-25
4
+ * Now generates an attr_accessible for all the columns in the table the model is generated from
data/README.md CHANGED
@@ -6,6 +6,14 @@ This bad boy will crank out models based on tables in an existing database.
6
6
 
7
7
  If you provide the namespace option, it will generate models in that namespace that inherit from a common base class. What's more, that base class will get it's connection information from the namespace name in database.yml. This means you can connect to both database at once to migrate data from one to the other.
8
8
 
9
+ ## Usage
10
+
11
+ 1. Add `gem "model_mill"` to your Gemfile
12
+ 2. `bundle install`
13
+ 3. `rails generate model_mill:models --namespace=whatever`
14
+
15
+ This will generate models from each table in the specified namespace. Each model will contain an `attr_accessible` for every attribute. Be sure to delete the ones that you do not need.
16
+
9
17
  ## Contributing to model_mill
10
18
 
11
19
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -14,6 +14,7 @@ module ModelMill
14
14
  discovered_tables.each do |table_name|
15
15
  @model_name = model_name_from_table_name table_name
16
16
  @model_file_name = model_file_name_from_table_name table_name
17
+ @columns = connection.columns(table_name)
17
18
  template 'model.rb', "app/models/#{options[:namespace] ? options[:namespace]+'/' : ''}#{@model_file_name}.rb"
18
19
  end
19
20
  puts %Q(config.autoload_paths += %W(\#{config.root}/app/models/#{options[:namespace].downcase})) if options[:namespace]
@@ -1,3 +1,4 @@
1
1
  class <%= options[:namespace] ? options[:namespace].camelize + '::' : '' %><%= @model_name %> < <%= options[:namespace] ? options[:namespace].camelize : 'ActiveRecord' %>::Base
2
+ attr_accessible <%= @columns.map(&:name).sort.map{|c| ":#{c}"}.join(', ') %>
2
3
  end
3
4
 
data/model_mill.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{model_mill}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joe Martinez"]
12
- s.date = %q{2011-01-24}
12
+ s.date = %q{2011-01-25}
13
13
  s.description = %q{Generates bare model files that can be used for a migration of legacy data to new models or to get a jump on development for an existing database}
14
14
  s.email = %q{joe@joemartinez.name}
15
15
  s.extra_rdoc_files = [
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.files = [
20
20
  ".document",
21
21
  ".rspec",
22
+ "CHANGELOG.md",
22
23
  "Gemfile",
23
24
  "Gemfile.lock",
24
25
  "LICENSE.txt",
@@ -33,7 +34,6 @@ Gem::Specification.new do |s|
33
34
  "spec/dummy/Rakefile",
34
35
  "spec/dummy/app/controllers/application_controller.rb",
35
36
  "spec/dummy/app/helpers/application_helper.rb",
36
- "spec/dummy/app/models/schema_migration.rb",
37
37
  "spec/dummy/app/views/layouts/application.html.erb",
38
38
  "spec/dummy/config.ru",
39
39
  "spec/dummy/config/application.rb",
@@ -77,7 +77,6 @@ Gem::Specification.new do |s|
77
77
  s.test_files = [
78
78
  "spec/dummy/app/controllers/application_controller.rb",
79
79
  "spec/dummy/app/helpers/application_helper.rb",
80
- "spec/dummy/app/models/schema_migration.rb",
81
80
  "spec/dummy/config/application.rb",
82
81
  "spec/dummy/config/boot.rb",
83
82
  "spec/dummy/config/environment.rb",
@@ -65,6 +65,10 @@ describe 'models_generator' do
65
65
  tests ModelMill::Generators::ModelsGenerator
66
66
  end
67
67
  @tables = %w(users widgets)
68
+ @table_columns = {
69
+ 'users' => %w(created_at email first_name id last_name updated_at),
70
+ 'widgets' => %w(color created_at id quantity updated_at)
71
+ }
68
72
  end
69
73
 
70
74
  after :each do
@@ -82,6 +86,16 @@ describe 'models_generator' do
82
86
  end
83
87
  end
84
88
  end
89
+
90
+ it 'adds attr_accessible declaration for all columns' do
91
+ GeneratorSpec.with_generator do |g|
92
+ g.run_generator
93
+ @tables.each do |tn|
94
+ file_contents("app/models/#{tn.singularize.underscore}.rb").
95
+ should match(/attr_accessible #{@table_columns[tn].sort.map{|c| ":#{c}"}.join(', ')}/)
96
+ end
97
+ end
98
+ end
85
99
  end
86
100
  end
87
101
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_mill
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joe Martinez
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-24 00:00:00 -05:00
18
+ date: 2011-01-25 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -167,6 +167,7 @@ extra_rdoc_files:
167
167
  files:
168
168
  - .document
169
169
  - .rspec
170
+ - CHANGELOG.md
170
171
  - Gemfile
171
172
  - Gemfile.lock
172
173
  - LICENSE.txt
@@ -181,7 +182,6 @@ files:
181
182
  - spec/dummy/Rakefile
182
183
  - spec/dummy/app/controllers/application_controller.rb
183
184
  - spec/dummy/app/helpers/application_helper.rb
184
- - spec/dummy/app/models/schema_migration.rb
185
185
  - spec/dummy/app/views/layouts/application.html.erb
186
186
  - spec/dummy/config.ru
187
187
  - spec/dummy/config/application.rb
@@ -258,7 +258,6 @@ summary: Generates ActiveRecord models from existing database tables.
258
258
  test_files:
259
259
  - spec/dummy/app/controllers/application_controller.rb
260
260
  - spec/dummy/app/helpers/application_helper.rb
261
- - spec/dummy/app/models/schema_migration.rb
262
261
  - spec/dummy/config/application.rb
263
262
  - spec/dummy/config/boot.rb
264
263
  - spec/dummy/config/environment.rb
@@ -1,3 +0,0 @@
1
- class SchemaMigration < ActiveRecord::Base
2
- end
3
-