Skip to content

Instantly share code, notes, and snippets.

@bcroesch
Created January 9, 2015 02:23
Show Gist options
  • Save bcroesch/263e345ecc26bee8db5d to your computer and use it in GitHub Desktop.
Save bcroesch/263e345ecc26bee8db5d to your computer and use it in GitHub Desktop.
component_name = Rails.root.to_s.split("/")[-3]
component_root = Rails.root.to_s.gsub("spec/dummy", "")
gemspec = <<-EOS
s.add_development_dependency \"rspec-rails\"
s.test_files = Dir["spec/**/*"]
EOS
inject_into_file "#{component_root}/#{component_name}.gemspec",
gemspec,
after: "s.add_development_dependency \"sqlite3\"\n"
engine_config = <<-EOS
config.autoload_paths += Dir["#{config.root}/lib/**/"]
config.generators do |g|
g.test_framework :rspec, fixture: false
g.fixture_replacement :factory_girl, dir: 'spec/factories'
end
initializer :append_migrations do |app|
unless app.root.to_s.match root.to_s
config.paths["db/migrate"].expanded.each do |expanded_path|
app.config.paths["db/migrate"] << expanded_path
end
end
end
EOS
inject_into_file "#{component_root}/lib/#{component_name}/engine.rb",
engine_config,
after: "isolate_namespace #{component_name.camelize}"
run "bundle install"
#!/bin/bash
rails plugin new ./components/$@ --mountable -T --dummy-path=spec/dummy
cd ./components/$@
bundle exec rake app:rails:template LOCATION=../component_template.rb
@hansondr
Copy link

hansondr commented Jun 4, 2015

Thanks for sharing Ben, I could be misreading your template but wouldn't you need to escape the interpolation on line 17?

config.autoload_paths += Dir["#{config.root}/lib/**/"]

to (or similar)

config.autoload_paths += Dir["\#{config.root}/lib/**/"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment