Class: Spree::Setup
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
Instance Method Summary collapse
- #bootstrap(config) ⇒ Object
- #create_admin_user(password = nil, email = nil) ⇒ Object
-
#load_sample_data ⇒ Object
Uses a special set of fixtures to load sample data.
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
23 24 25 |
# File 'lib/spree/setup.rb', line 23 def config @config end |
Class Method Details
.bootstrap(config) ⇒ Object
12 13 14 15 16 |
# File 'lib/spree/setup.rb', line 12 def bootstrap(config) setup = new setup.bootstrap(config) setup end |
Instance Method Details
#bootstrap(config) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/spree/setup.rb', line 25 def bootstrap(config) # make sure the product images directory exists FileUtils.mkdir_p "#{RAILS_ROOT}/public/images/products/" @config = config @admin = create_admin_user(config[:admin_password], config[:admin_email]) load_sample_data if sample_data? announce "Finished.\n\n" end |
#create_admin_user(password = nil, email = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/spree/setup.rb', line 35 def create_admin_user(password=nil, email=nil) unless email and password announce "Create the admin user (press enter for defaults)." #name = prompt_for_admin_name unless name email = prompt_for_admin_email unless email password = prompt_for_admin_password unless password end attributes = { :password => password, :password_confirmation => password, :email => email, :login => email } admin = User.create(attributes) # create an admin role and and assign the admin user to that role role = Role.create(:name => 'admin') admin.roles << role admin.save admin end |
#load_sample_data ⇒ Object
Uses a special set of fixtures to load sample data
58 59 60 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 |
# File 'lib/spree/setup.rb', line 58 def load_sample_data # load initial database fixtures (in db/sample/*.yml) into the current environment's database ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym) Dir.glob(File.join(SPREE_ROOT, "db", 'sample', '*.{yml,csv}')).each do |fixture_file| Fixtures.create_fixtures("#{SPREE_ROOT}/db/sample", File.basename(fixture_file, '.*')) end # make product images available to the app target = "#{RAILS_ROOT}/public/assets/products/" source = "#{SPREE_ROOT}/lib/tasks/sample/products/" Find.find(source) do |f| # omit hidden directories (SVN, etc.) if File.basename(f) =~ /^[.]/ Find.prune next end src_path = source + f.sub(source, '') target_path = target + f.sub(source, '') if File.directory?(f) FileUtils.mkdir_p target_path else FileUtils.cp src_path, target_path end end announce "Sample products have been loaded into to the store" end |