Class: Spree::DummyGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/spree/dummy/dummy_generator.rb

Constant Summary

PASSTHROUGH_OPTIONS =
[
  :skip_active_record, :skip_javascript, :database, :javascript, :quiet, :pretend, :force, :skip
]

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) database (readonly)

Returns the value of attribute database



82
83
84
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 82

def database
  @database
end

- (Object) lib_name (readonly)

Returns the value of attribute lib_name



81
82
83
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 81

def lib_name
  @lib_name
end

Class Method Details

+ (Object) source_paths



12
13
14
15
16
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 12

def self.source_paths
  paths = superclass.source_paths
  paths << File.expand_path('../templates', __FILE__)
  paths.flatten
end

Instance Method Details

- (Object) clean_up



18
19
20
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 18

def clean_up
  remove_directory_if_exists(dummy_path)
end

- (Object) generate_test_dummy



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 26

def generate_test_dummy
  # calling slice on a Thor::CoreExtensions::HashWithIndifferentAccess
  # object has been known to return nil
  opts = {}.merge(options).slice(*PASSTHROUGH_OPTIONS)
  opts[:database] = 'sqlite3' if opts[:database].blank?
  opts[:force] = true
  opts[:skip_bundle] = true

  puts "Generating dummy Rails application..."
  invoke Rails::Generators::AppGenerator,
    [File.expand_path(dummy_path, destination_root)], opts
end

- (Object) test_dummy_clean



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 64

def test_dummy_clean
  inside dummy_path do
    remove_file ".gitignore"
    remove_file "doc"
    remove_file "Gemfile"
    remove_file "lib/tasks"
    remove_file "app/assets/images/rails.png"
    remove_file "app/assets/javascripts/application.js"
    remove_file "public/index.html"
    remove_file "public/robots.txt"
    remove_file "README"
    remove_file "test"
    remove_file "vendor"
    remove_file "spec"
  end
end

- (Object) test_dummy_config



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 39

def test_dummy_config
  @lib_name = options[:lib_name]
  @database = options[:database]

  template "rails/database.yml", "#{dummy_path}/config/database.yml", force: true
  template "rails/boot.rb", "#{dummy_path}/config/boot.rb", force: true
  template "rails/application.rb", "#{dummy_path}/config/application.rb", force: true
  template "rails/routes.rb", "#{dummy_path}/config/routes.rb", force: true
  template "rails/test.rb", "#{dummy_path}/config/environments/test.rb", force: true
  template "rails/script/rails", "#{dummy_path}/spec/dummy/script/rails", force: true

  # FIXME: We aren't ready for rails 5 defaults
  remove_file "#{dummy_path}/config/initializers/new_framework_defaults.rb"
end

- (Object) test_dummy_inject_extension_requirements



54
55
56
57
58
59
60
61
62
# File 'lib/generators/spree/dummy/dummy_generator.rb', line 54

def test_dummy_inject_extension_requirements
  if DummyGeneratorHelper.inject_extension_requirements
    inside dummy_path do
      inject_require_for('spree_frontend')
      inject_require_for('spree_backend')
      inject_require_for('spree_api')
    end
  end
end