toastyapps-migratory 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +11 -5
- data/Rakefile +2 -1
- data/generators/model/model_generator.rb +24 -6
- data/generators/model/templates/migration.rb +1 -1
- metadata +3 -3
data/README.textile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
h1.
|
1
|
+
h1. Migratory
|
2
2
|
|
3
3
|
h2. Usage
|
4
4
|
|
@@ -6,12 +6,18 @@ Migratory overrides the default rails model migration and gives you the ability
|
|
6
6
|
|
7
7
|
h3. Specify Default Values
|
8
8
|
|
9
|
-
script/generate model User username:string password_encrypted:string email:string
|
9
|
+
script/generate model User username:string password_encrypted:string email:string _**is_admin:boolean:false**_ _**rating:integer:0**_ _**role:string:"member"**_
|
10
10
|
|
11
|
-
script/generate resource User username:string password_encrypted:string email:string
|
11
|
+
script/generate resource User username:string password_encrypted:string email:string _**is_admin:boolean:false**_ _**rating:integer:0**_ _**role:string:"member"**_
|
12
12
|
|
13
13
|
h3. Specify Indexes
|
14
14
|
|
15
|
-
script/generate model User
|
15
|
+
script/generate model User _***username:string**_ password_encrypted:string _***email:string**_ is_admin:boolean:false
|
16
16
|
|
17
|
-
script/generate resource User
|
17
|
+
script/generate resource User _***username:string**_ password_encrypted:string _***email:string**_ is_admin:boolean:false
|
18
|
+
|
19
|
+
h3. Specify Limit, Precision, and Scale
|
20
|
+
|
21
|
+
script/generate model Product _**name:string<notextile>[30]</notextile>**_ _**cost:decimal<notextile>[10,2]</notextile>:0.00**_
|
22
|
+
|
23
|
+
script/generate resource Product _**name:string<notextile>[30]</notextile>**_ _**cost:decimal<notextile>[10,2]</notextile>:0.00**_
|
data/Rakefile
CHANGED
@@ -3,8 +3,9 @@ require 'rake/testtask'
|
|
3
3
|
|
4
4
|
gem_spec = Gem::Specification.new do |gem_spec|
|
5
5
|
gem_spec.name = 'migratory'
|
6
|
-
gem_spec.version = '0.0.
|
6
|
+
gem_spec.version = '0.0.2'
|
7
7
|
gem_spec.summary = 'Rails migration extender for default values and adding indexes'
|
8
|
+
gem_spec.description = 'Rails migration extender for default values and adding indexes'
|
8
9
|
gem_spec.email = 'matt@toastyapps.com'
|
9
10
|
gem_spec.homepage = 'http://github.com/toastyapps/migratory'
|
10
11
|
gem_spec.authors = ["Matthew Mongeau"]
|
@@ -1,19 +1,37 @@
|
|
1
1
|
module Rails
|
2
2
|
module Generator
|
3
3
|
class GeneratedAttribute
|
4
|
-
attr_accessor :default, :is_indexed
|
4
|
+
attr_accessor :default, :is_indexed, :limit, :precision, :scale
|
5
5
|
|
6
6
|
def initialize_with_migratory(name, type, default = nil)
|
7
7
|
@default = default
|
8
8
|
@is_indexed = (name =~ /^\*/) && true
|
9
|
-
|
9
|
+
if type =~ /\[.*?\]/
|
10
|
+
details = type.match(/\[(.*?)\]/)[1]
|
11
|
+
if details =~ /,/
|
12
|
+
@precision, @scale = details.split(/,/).map(&:to_i)
|
13
|
+
else
|
14
|
+
case type.gsub(/\[.*?\]/, '').to_s
|
15
|
+
when 'string','text','binary','integer' then @limit = details.to_i
|
16
|
+
when 'decimal', 'float' then @precision = details.to_i
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
initialize_without_migratory(name.gsub(/^\*/, ''), type.gsub(/\[.*?\]/, ''))
|
10
21
|
end
|
11
22
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
23
|
+
def options
|
24
|
+
options = []
|
25
|
+
options << ", :limit => #{@limit}" if @limit
|
26
|
+
options << ", :precision => #{@precision}" if @precision
|
27
|
+
options << ", :scale => #{@scale}" if @scale
|
28
|
+
if @default
|
29
|
+
options << case @type.to_s
|
30
|
+
when 'string', 'text', 'date', 'datetime', 'time', 'timestamp' then ', :default => "'+@default+'"'
|
31
|
+
else ", :default => #{@default}"
|
32
|
+
end
|
16
33
|
end
|
34
|
+
options.join('')
|
17
35
|
end
|
18
36
|
|
19
37
|
alias_method_chain :initialize, :migratory
|
@@ -2,7 +2,7 @@ class <%= migration_name %> < ActiveRecord::Migration
|
|
2
2
|
def self.up
|
3
3
|
create_table :<%= table_name %> do |t|
|
4
4
|
<% for attribute in attributes -%>
|
5
|
-
t.<%= attribute.type %> :<%= attribute.name %><%=
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %><%= attribute.options %>
|
6
6
|
<% end -%>
|
7
7
|
<% unless options[:skip_timestamps] %>
|
8
8
|
t.timestamps
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toastyapps-migratory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Mongeau
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-01 21:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description:
|
16
|
+
description: Rails migration extender for default values and adding indexes
|
17
17
|
email: matt@toastyapps.com
|
18
18
|
executables: []
|
19
19
|
|