Class: SprangularCli::Installer

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

Instance Method Summary collapse

Instance Method Details

#add_gemsObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/sprangular_cli/installer.rb', line 90

def add_gems
  inside @app_path do
    prepend_file 'Gemfile', "source 'https://rails-assets.org'\n", verbose: false

    gem 'spree_core',        @spree_gem_options
    gem 'spree_api',         @spree_gem_options
    gem 'spree_backend',     @spree_gem_options
    gem 'spree_sample',      @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, github: 'spree/spree_gateway', branch: '2-4-stable'
    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, github: 'spree/spree_auth_devise', branch: '2-4-stable'
    end

    if options[:edge]
      gem :sprangular, github: 'sprangular/sprangular'
    else
      gem :sprangular, version: options[:version]
    end

    run 'bundle install', capture: true
  end
end

#ask_questionsObject



61
62
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
# File 'lib/sprangular_cli/installer.rb', line 61

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_sprangularObject



134
135
136
137
138
# File 'lib/sprangular_cli/installer.rb', line 134

def initialize_sprangular
  inside @app_path do
    run "rails generate sprangular:install", verbose: false
  end
end

#initialize_spreeObject



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/sprangular_cli/installer.rb', line 121

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



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

def prepare_options
  @spree_gem_options = {}

  if options[:edge] || options[:branch]
    @spree_gem_options[:github] = 'spree/spree'
  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[:spree_version]
    @spree_gem_options[:version] = options[:spree_version]
  else
    version = '2.4'
    @spree_gem_options[:version] = version.to_s
  end

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

#verify_image_magickObject



29
30
31
32
33
34
# File 'lib/sprangular_cli/installer.rb', line 29

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

#verify_railsObject



36
37
38
# File 'lib/sprangular_cli/installer.rb', line 36

def verify_rails
  create_rails_app unless rails_project?
end