toastyapps-migratory 0.0.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.
data/README.textile ADDED
@@ -0,0 +1,17 @@
1
+ h1. Thinking Sphinx
2
+
3
+ h2. Usage
4
+
5
+ Migratory overrides the default rails model migration and gives you the ability to do the following
6
+
7
+ h3. Specify Default Values
8
+
9
+ script/generate model User username:string password_encrypted:string email:string *is_admin:boolean:false* *rating:integer:0* *role:string:"member"*
10
+
11
+ script/generate resource User username:string password_encrypted:string email:string *is_admin:boolean:false* *rating:integer:0* *role:string:"member"*
12
+
13
+ h3. Specify Indexes
14
+
15
+ script/generate model User **username:string* password_encrypted:string **email:string* is_admin:boolean:false
16
+
17
+ script/generate resource User **username:string* password_encrypted:string **email:string* is_admin:boolean:false
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
4
+ gem_spec = Gem::Specification.new do |gem_spec|
5
+ gem_spec.name = 'migratory'
6
+ gem_spec.version = '0.0.1'
7
+ gem_spec.summary = 'Rails migration extender for default values and adding indexes'
8
+ gem_spec.email = 'matt@toastyapps.com'
9
+ gem_spec.homepage = 'http://github.com/toastyapps/migratory'
10
+ gem_spec.authors = ["Matthew Mongeau"]
11
+ gem_spec.files = FileList["[A-Z]*", "{generators,lib}/**/*"]
12
+ end
13
+
14
+ desc "Generate a gemspec file"
15
+ task :gemspec do
16
+ File.open("#{gem_spec.name}.gemspec", "w") do |f|
17
+ f.write gem_spec.to_yaml
18
+ end
19
+ end
@@ -0,0 +1,68 @@
1
+ module Rails
2
+ module Generator
3
+ class GeneratedAttribute
4
+ attr_accessor :default, :is_indexed
5
+
6
+ def initialize_with_migratory(name, type, default = nil)
7
+ @default = default
8
+ @is_indexed = (name =~ /^\*/) && true
9
+ initialize_without_migratory(name.gsub!(/^\*/, ''), type)
10
+ end
11
+
12
+ def default_value
13
+ case @type.to_s
14
+ when 'string', 'text', 'date', 'datetime', 'time', 'timestamp' then '"'+@default+'"'
15
+ else @default
16
+ end
17
+ end
18
+
19
+ alias_method_chain :initialize, :migratory
20
+ end
21
+ end
22
+ end
23
+
24
+ class ModelGenerator < Rails::Generator::NamedBase
25
+ default_options :skip_timestamps => false, :skip_migration => false, :skip_fixture => false
26
+
27
+ def manifest
28
+ record do |m|
29
+ # Check for class naming collisions.
30
+ m.class_collisions class_name, "#{class_name}Test"
31
+
32
+ # Model, test, and fixture directories.
33
+ m.directory File.join('app/models', class_path)
34
+ m.directory File.join('test/unit', class_path)
35
+ m.directory File.join('test/fixtures', class_path)
36
+
37
+ # Model class, unit test, and fixtures.
38
+ m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
39
+ m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_test.rb")
40
+
41
+ unless options[:skip_fixture]
42
+ m.template 'fixtures.yml', File.join('test/fixtures', "#{table_name}.yml")
43
+ end
44
+
45
+ unless options[:skip_migration]
46
+ m.migration_template 'migration.rb', 'db/migrate', :assigns => {
47
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
48
+ }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
49
+ end
50
+ end
51
+ end
52
+
53
+ protected
54
+ def banner
55
+ "Usage: #{$0} #{spec.name} ModelName [field:type, field:type]"
56
+ end
57
+
58
+ def add_options!(opt)
59
+ opt.separator ''
60
+ opt.separator 'Options:'
61
+ opt.on("--skip-timestamps",
62
+ "Don't add timestamps to the migration file for this model") { |v| options[:skip_timestamps] = v }
63
+ opt.on("--skip-migration",
64
+ "Don't generate a migration file for this model") { |v| options[:skip_migration] = v }
65
+ opt.on("--skip-fixture",
66
+ "Don't generation a fixture file for this model") { |v| options[:skip_fixture] = v}
67
+ end
68
+ end
@@ -0,0 +1,19 @@
1
+ # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2
+
3
+ <% unless attributes.empty? -%>
4
+ one:
5
+ <% for attribute in attributes -%>
6
+ <%= attribute.name %>: <%= attribute.default %>
7
+ <% end -%>
8
+
9
+ two:
10
+ <% for attribute in attributes -%>
11
+ <%= attribute.name %>: <%= attribute.default %>
12
+ <% end -%>
13
+ <% else -%>
14
+ # one:
15
+ # column: value
16
+ #
17
+ # two:
18
+ # column: value
19
+ <% end -%>
@@ -0,0 +1,20 @@
1
+ class <%= migration_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %> do |t|
4
+ <% for attribute in attributes -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %><%= ", :default => #{attribute.default_value}" if attribute.default %>
6
+ <% end -%>
7
+ <% unless options[:skip_timestamps] %>
8
+ t.timestamps
9
+ <% end -%>
10
+
11
+ <% for attribute in attributes -%><% if attribute.is_indexed -%>
12
+ add_index :<%= attribute.name %>
13
+ <% end -%><% end -%>
14
+ end
15
+ end
16
+
17
+ def self.down
18
+ drop_table :<%= table_name %>
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ <% attributes.select(&:reference?).each do |attribute| -%>
3
+ belongs_to :<%= attribute.name %>
4
+ <% end -%>
5
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class <%= class_name %>Test < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
data/lib/README ADDED
@@ -0,0 +1 @@
1
+ Nothing to see here
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: toastyapps-migratory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Mongeau
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-30 21:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: matt@toastyapps.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - Rakefile
26
+ - README.textile
27
+ - generators/model
28
+ - generators/model/model_generator.rb
29
+ - generators/model/templates
30
+ - generators/model/templates/fixtures.yml
31
+ - generators/model/templates/migration.rb
32
+ - generators/model/templates/model.rb
33
+ - generators/model/templates/unit_test.rb
34
+ - lib/README
35
+ has_rdoc: true
36
+ homepage: http://github.com/toastyapps/migratory
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.3.5
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Rails migration extender for default values and adding indexes
63
+ test_files: []
64
+