forked from calagator/calagator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rails_template.rb
47 lines (38 loc) · 1.56 KB
/
rails_template.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
47
require 'rubygems'
require 'pathname'
RAILS_REQUIREMENT = '~> 4.2'.freeze
def assert_minimum_rails_version
requirement = Gem::Requirement.new(RAILS_REQUIREMENT)
rails_version = Gem::Version.new(Rails::VERSION::STRING)
return if requirement.satisfied_by?(rails_version)
puts "Calagator requires Rails #{RAILS_REQUIREMENT}. You are using #{rails_version}."
exit 1
end
assert_minimum_rails_version
generating_dummy = ARGV.include? '--dummy'
calagator_checkout = Pathname.new(File.expand_path(__dir__))
relative_calagator_path = calagator_checkout.relative_path_from(Pathname.new(destination_root))
if options[:database] == 'postgresql' && ARGV.any? { |arg| arg =~ /--postgres-username=(\w+)/ }
inside('config') do
run "sed -e 's/username: .*/username: #{Regexp.last_match(1)}/' -i -- database.yml"
end
end
# FactoryBot and Faker are required for Calagator's db:seed task
spec = Gem::Specification.load(File.expand_path('calagator.gemspec', __dir__))
spec ||= Gem::Specification.find_by(name: 'calagator')
required_dev_gems = %w[factory_bot_rails faker]
gem_group :development, :test do
if spec
spec_dependencies = spec.development_dependencies.select { |dep| required_dev_gems.include?(dep.name) }
spec_dependencies.each do |dep|
gem dep.name, dep.requirement.to_s
end
else
required_dev_gems.each { |gem_name| gem gem_name }
end
end
gem 'calagator', (generating_dummy && { path: relative_calagator_path.to_s })
run 'bundle install'
rake 'db:create'
generate 'calagator:install', (generating_dummy && '--dummy')
generate 'sunspot_rails:install'