Skip to content

Instantly share code, notes, and snippets.

@fd
Created May 8, 2009 08:37
Show Gist options
  • Save fd/108709 to your computer and use it in GitHub Desktop.
Save fd/108709 to your computer and use it in GitHub Desktop.
Part 1 in our Arrrrcamp presentation
# sudo gem source -a http://gems.github.com
# sudo gem install thoughtbot-paperclip giraffesoft-resource_controller restfulx
def mate(path='')
run "mate #{path}"
end
def step(name='')
$step_count ||= 0
$step_count += 1
clear
until yes?("Continue to step #{$step_count}: #{name}")
end
yield
end
def restart
in_root { run 'touch tmp/restart.txt' }
end
def sopen(what, delay=2)
Thread.new do
sleep delay
run "open #{what}"
end
end
def clear
system 'clear'
end
step 'required gems' do
gem "restfulx"
gem 'thoughtbot-paperclip', :lib => 'paperclip',
:source => 'http://gems.github.com'
gem 'giraffesoft-resource_controller', :lib => 'resource_controller',
:source => 'http://gems.github.com'
mate '.'
mate 'config/environment.rb'
end
step 'generate restfulx configuration' do
generate('rx_config')
mate 'config/restfulx.yml'
end
step 'configure restfulx' do
gsub_file('config/restfulx.yml', /controller_pattern:\s*'default'/,
'controller_pattern: \'resource_controller\'')
mate
end
step 'write the db/model.yml file' do
file 'db/model.yml', <<-CODE
gallery:
- name: string
- description: text
- has_many: [pictures]
picture:
- belongs_to: [gallery]
- attachment_field: [file]
- description: text
CODE
mate 'db/model.yml'
end
step 'generate the scaffold from db/model.yml' do
in_root { run 'rm app/flex/*.mxml' }
generate('rx_yaml_scaffold')
migration_path = Dir.glob('db/migrate/*_create_pictures.rb').last
gsub_file(migration_path, /avatar_/,
'file_')
mate
end
step 'tweak our models' do
gsub_file('app/models/picture.rb', /def attachment_url/,
"validates_presence_of :gallery\n def attachment_url")
gsub_file('app/models/picture.rb', /def attachment_url/,
"validates_attachment_presence :file\n def attachment_url")
gsub_file('app/models/picture.rb', /def attachment_url/,
"\n def attachment_url")
gsub_file('app/models/gallery.rb', /\bend\b/,
" validates_presence_of :name\nend")
mate
end
step 'migrate and build swf' do
rake('db:migrate')
rake('rx:flex:build')
mate
end
step 'migrate and build swf' do
sopen 'http://localhost:3000'
run 'script/server'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment