lib/spree_cmd/installer.rb in spree_cmd-1.0.7 vs lib/spree_cmd/installer.rb in spree_cmd-1.1.0.rc1
- old
+ new
@@ -1,14 +1,15 @@
module SpreeCmd
class Installer < Thor::Group
include Thor::Actions
- desc "Creates a new rails project with a spree store"
+ desc 'Creates a new rails project with a spree store'
argument :app_path, :type => :string, :desc => 'rails app_path', :default => '.'
- class_option :auto_accept, :type => :boolean, :aliases => '-A', :desc => "Answer yes to all prompts"
+ class_option :auto_accept, :type => :boolean, :aliases => '-A',
+ :desc => 'Answer yes to all prompts'
class_option :skip_install_data, :type => :boolean, :default => false,
:desc => 'Skip running migrations and loading seed and sample data'
class_option :version, :type => :string, :default => 'current',
@@ -22,11 +23,11 @@
class_option :branch, :type => :string, :desc => 'Spree gem git branch'
class_option :tag, :type => :string, :desc => 'Spree gem git tag'
def verify_rails
unless is_rails_project?
- say "#{@app_path} rails project not found"
+ say "#{@app_path} is not a rails project."
exit(1)
end
end
def prepare_options
@@ -43,21 +44,21 @@
@spree_gem_options[:tag] = options[:tag] if options[:tag]
end
end
def ask_questions
- @install_default_gateways = ask_with_default("Would you like to install the default gateways?")
+ @install_default_gateways = ask_with_default('Would you like to install the default gateways?')
if options[:skip_install_data]
@run_migrations = false
@load_seed_data = false
@load_sample_data = false
else
- @run_migrations = ask_with_default("Would you like to run the migrations?")
+ @run_migrations = ask_with_default('Would you like to run the migrations?')
if @run_migrations
- @load_seed_data = ask_with_default("Would you like to load the seed data?")
- @load_sample_data = ask_with_default("Would you like to load the sample data?")
+ @load_seed_data = ask_with_default('Would you like to load the seed data?')
+ @load_sample_data = ask_with_default('Would you like to load the sample data?')
else
@load_seed_data = false
@load_sample_data = false
end
end
@@ -95,61 +96,61 @@
run "rails generate spree:install #{spree_options.join(' ')}", :verbose => false
end
end
def precompile_assets
- say_status :precompiling, "assets"
+ say_status :precompiling, 'assets'
inside @app_path do
run 'bundle exec rake assets:precompile', :verbose => false
end
end
private
- def gem(name, options={})
- say_status :gemfile, name
- parts = ["'#{name}'"]
- options.each {|key, value| parts << ":#{key} => '#{value}'" }
- append_file "Gemfile", "gem #{parts.join(', ')}\n", :verbose => false
- end
+ def gem(name, options={})
+ say_status :gemfile, name
+ parts = ["'#{name}'"]
+ options.each { |key, value| parts << ":#{key} => '#{value}'" }
+ append_file 'Gemfile', "gem #{parts.join(', ')}\n", :verbose => false
+ end
- def ask_with_default(message, default='yes')
- return true if options[:auto_accept]
+ def ask_with_default(message, default = 'yes')
+ return true if options[:auto_accept]
- valid = false
- until valid
- response = ask "#{message} (yes/no) [#{default}]"
- response = default if response.empty?
- valid = (response =~ /\Ay(?:es)?|no?\Z/i)
+ valid = false
+ until valid
+ response = ask "#{message} (yes/no) [#{default}]"
+ response = default if response.empty?
+ valid = (response =~ /\Ay(?:es)?|no?\Z/i)
+ end
+ response.downcase[0] == ?y
end
- response.downcase[0] == ?y
- end
- def ask_string(message, default, valid_regex=/\w/)
- return default if options[:auto_accept]
- valid = false
- until valid
- response = ask "#{message} [#{default}]"
- response = default if response.empty?
- valid = (response =~ valid_regex)
+ def ask_string(message, default, valid_regex = /\w/)
+ return default if options[:auto_accept]
+ valid = false
+ until valid
+ response = ask "#{message} [#{default}]"
+ response = default if response.empty?
+ valid = (response =~ valid_regex)
+ end
+ response
end
- response
- end
- def create_rails_app
- say :create, @app_path
+ def create_rails_app
+ say :create, @app_path
- rails_cmd = "rails new #{@app_path} --skip-bundle"
- if options[:template]
- rails_cmd += " -m #{options[:template]}"
+ rails_cmd = "rails new #{@app_path} --skip-bundle"
+ if options[:template]
+ rails_cmd += " -m #{options[:template]}"
+ end
+ if options[:database]
+ rails_cmd += " -d #{options[:database]}"
+ end
+ run(rails_cmd)
end
- if options[:database]
- rails_cmd += " -d #{options[:database]}"
- end
- run(rails_cmd)
- end
- def is_rails_project?
- File.exists? File.join(@app_path, 'script', 'rails')
- end
+ def is_rails_project?
+ File.exists? File.join(@app_path, 'script', 'rails')
+ end
end
end