Class: SpreeCmd::Installer

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/spree_cmd/installer.rb

Instance Method Summary collapse

Instance Method Details

#add_gemsObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/spree_cmd/installer.rb', line 92

def add_gems
  inside @app_path do

    gem :spree, @spree_gem_options

    if @install_default_gateways && @spree_gem_options[:branch]
      gem :spree_gateway, github: 'spree/spree_gateway', branch: @spree_gem_options[:branch]
    elsif @install_default_gateways
      gem :spree_gateway, version: '3.0.0'
    end

    if @install_default_auth && @spree_gem_options[:branch]
      gem :spree_auth_devise, github: 'spree/spree_auth_devise', branch: @spree_gem_options[:branch]
    elsif @install_default_auth
      gem :spree_auth_devise, version: '3.0.0'
    end

    run 'bundle install', :capture => true
  end
end

#ask_questionsObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/spree_cmd/installer.rb', line 63

def ask_questions
  @install_default_gateways = ask_with_default('Would you like to install the default gateways? (Recommended)')
  @install_default_auth = ask_with_default('Would you like to install the default authentication system?')

  if @install_default_auth
    @user_class = "Spree::User"
  else
    @user_class = ask("What is the name of the class representing users within your application? [User]")
    if @user_class.blank?
      @user_class = "User"
    end
  end

  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?')
    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?')
    else
      @load_seed_data = false
      @load_sample_data = false
    end
  end
end

#initialize_spreeObject



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/spree_cmd/installer.rb', line 113

def initialize_spree
  spree_options = []
  spree_options << "--migrate=#{@run_migrations}"
  spree_options << "--seed=#{@load_seed_data}"
  spree_options << "--sample=#{@load_sample_data}"
  spree_options << "--user_class=#{@user_class}"
  spree_options << "--auto_accept" if options[:auto_accept]

  inside @app_path do
    run "rails generate spree:install #{spree_options.join(' ')}", :verbose => false
  end
end

#prepare_optionsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/spree_cmd/installer.rb', line 42

def prepare_options
  @spree_gem_options = {}

  if options[:edge] || options[:branch]
    @spree_gem_options[:git] = 'https://github.com/spree/spree.git'
  elsif options[:path]
    @spree_gem_options[:path] = options[:path]
  elsif options[:git]
    @spree_gem_options[:git] = options[:git]
    @spree_gem_options[:ref] = options[:ref] if options[:ref]
    @spree_gem_options[:tag] = options[:tag] if options[:tag]
  elsif options[:version]
    @spree_gem_options[:version] = options[:version]
  else
    version = Gem.loaded_specs['spree_cmd'].version
    @spree_gem_options[:version] = version.to_s
  end

  @spree_gem_options[:branch] = options[:branch] if options[:branch]
end

#verify_image_magickObject



35
36
37
38
39
40
# File 'lib/spree_cmd/installer.rb', line 35

def verify_image_magick
  unless image_magick_installed?
    say "Image magick must be installed."
    exit 1
  end
end

#verify_railsObject



28
29
30
31
32
33
# File 'lib/spree_cmd/installer.rb', line 28

def verify_rails
  unless rails_project?
    say "#{@app_path} is not a rails project."
    exit 1
  end
end