-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaffold.rb
48 lines (33 loc) · 1.01 KB
/
scaffold.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
gem 'ParseTree', :require => 'parse_tree'
gem 'ruby2ruby'
gem "simple_form"
gem 'inherited_resources', '1.1.2'
in_root do
run 'bundle install'
run 'rvm reload'
end
in_root do
generate 'simple_form:install'
end
require 'rubygems'
require 'parse_tree'
require 'parse_tree_extensions'
require 'ruby2ruby'
def create_model(name, *arr, &block)
name = name.to_s.singularize
generate(:scaffold, name, arr.join(' '))
sentinel = /class [a-z_:]+ < ActiveRecord::Base/i
data = block.to_ruby.gsub(/(^proc \{)|(\}$)/, '').strip if block_given?
in_root do
inject_into_file "app/models/#{name}.rb", "\n #{data}", :after => sentinel, :verbose => false
log :model, "Model #{name} injectin info"
end
end
create_model :category, "title:string", "body:text" do
has_and_belongs_to_many :products
end
create_model :product, "title:string", "body:text" do
has_and_belongs_to_many :categories
end
generate :migration, 'CreateCategoriesProducts', 'category_id:integer product_id:integer'
rake 'db:migrate'