Skip to content

Commit

Permalink
added migrations only option
Browse files Browse the repository at this point in the history
  • Loading branch information
brantwedel committed Mar 17, 2014
1 parent e1d446f commit 55232d1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
yaddl (0.0.4)
yaddl (0.0.5)
rails (~> 4.0.0)

GEM
Expand Down
7 changes: 6 additions & 1 deletion lib/tasks/yaddl.rake
Expand Up @@ -11,7 +11,12 @@ namespace :yaddl do
y = Yaddl::Generator::load("#{Rails.root}/db/*.yaddl")
y.generate("--force --no-assets --skip-migration --helpers=false")
end
desc "Regenerate models, skips migrations"
desc "Regenerate migrations only, skips models"
task :migrations do
y = Yaddl::Generator::load("#{Rails.root}/db/*.yaddl")
y.generate("--migrations-only")
end
desc "Regenerate models only, skips migrations"
task :models do
y = Yaddl::Generator::load("#{Rails.root}/db/*.yaddl")
y.generate("--no-scaffolds")
Expand Down
29 changes: 28 additions & 1 deletion lib/yaddl.rb
@@ -1,5 +1,8 @@
module Yaddl
require "yaddl/railtie" if defined?(Rails)

require "rails"
require "rails/generators/migration"
class Generator

attr_accessor :markup
Expand Down Expand Up @@ -92,8 +95,32 @@ def scaffolds(options = "")
sc = "rails g scaffold #{name} " + model['attributes'].reject{ | k, v| v['hidden'] }.map{ |k,v| k + ':' + v['type'].sub(/yaml|hash|object|cache/i,"text") }.join(' ') + " " + model['belongs_to'].reject{ | k, v| v['hidden'] }.map{ |k,v| k + ':references' + (v['polymorphic'] ? "{polymorphic}" : "") }.join(' ')
puts("form: #{sc}") unless @quiet
`#{sc} #{options.gsub("--force","")} --skip --no-migrations`
end if !options.include?("--no-scaffold")
end if !options.include?("--no-scaffold") && !options.include?("--migrations-only")

models.reject{ |k,v| k[0] == "@"}.each do |name,model|
model['has_one'] ||= {}
model['has_many'] ||= {}
model['belongs_to'] ||= {}
model['attributes'] ||= {}
model['methods'] ||= {}
model['code'] ||= {}
model['code']['top'] ||= []
model['code']['before'] ||= []
model['code']['after'] ||= []
model['code']['controller'] ||= []
sc = "rails g model #{name} " + model['attributes'].map{ |k,v| k + ':' + v['type'].sub(/yaml|hash|object|cache/i,"text") }.join(' ') + " " + model['belongs_to'].map{ |k,v| k + ':references' + (v['polymorphic'] ? "{polymorphic}" : "") }.join(' ')
puts("migration: cd #{Rails::root} && #{sc} --skip")# unless @quiet
`cd #{Rails::root} && #{sc} --skip --no-test-framework`
end if options.include?("--migrations-only")

if options.include?("--migrations-only")
cleanup(ddl: true, mixins: false)
File.open("#{Rails.root}/db/schema.yaml", "w") do |f|
f.write models.to_yaml
end
puts("","--- DATA #{models.to_yaml}","") unless @quiet
return
end

models.reject{ |k,v| k[0] == "@"}.each do |name,model|
model['has_one'] ||= {}
Expand Down
2 changes: 1 addition & 1 deletion lib/yaddl/version.rb
@@ -1,3 +1,3 @@
module Yaddl
VERSION = "0.0.5"
VERSION = "0.0.6"
end
1 change: 1 addition & 0 deletions test/yaddl_test.rb
Expand Up @@ -11,6 +11,7 @@ class YaddlTest < ActiveSupport::TestCase
=to_s{name}
*RelatedModel"
y.generate("--no-scaffolds --quiet")
y.generate("--migrations-only --quiet")
assert_file "app/models/test_model.rb", "class TestModel < ActiveRecord::Base
has_many :related_models, dependent: :destroy
Expand Down

0 comments on commit 55232d1

Please sign in to comment.