Class: Jobshop::DummyApp

Inherits:
Object
  • Object
show all
Defined in:
lib/jobshop/dummy_app.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDummyApp

Returns a new instance of DummyApp.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jobshop/dummy_app.rb', line 42

def initialize
  options = {
    api: false,
    database: "postgresql",
    skip_gemfile: true,
    skip_git: true,
    skip_bundle: true,
    skip_listen: true,
    skip_test: true,
    template: DummyApp.template
  }

  DummyApp.destroy! if DummyApp.exist?
  Rails::Generators::AppGenerator.new([ DummyApp.path ], options).invoke_all
end

Class Method Details

.constant_nameObject



27
28
29
30
# File 'lib/jobshop/dummy_app.rb', line 27

def constant_name
  @constant_name = File.basename(path)
    .gsub(/\W/, '_').squeeze('_').camelize
end

.destroy!Object



18
19
20
21
# File 'lib/jobshop/dummy_app.rb', line 18

def destroy!
  FileUtils.rmtree(path)
  Object.send(:remove_const, constant_name)
end

.exist?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/jobshop/dummy_app.rb', line 14

def exist?
  Dir.exist?(path)
end

.pathObject



23
24
25
# File 'lib/jobshop/dummy_app.rb', line 23

def path
  @path ||= File.expand_path("spec/dummy-#{Rails::VERSION::STRING}")
end

.rakefileObject



32
33
34
# File 'lib/jobshop/dummy_app.rb', line 32

def rakefile
  File.join(path, "Rakefile")
end

.require_environment!Object



6
7
8
9
10
11
12
# File 'lib/jobshop/dummy_app.rb', line 6

def require_environment!
  if exist?
    require File.join(path, "config/environment")
  else
    abort("Dummy app does not exist. Please run `rake jobshop:dummy` to create it.")
  end
end

.templateObject



36
37
38
39
# File 'lib/jobshop/dummy_app.rb', line 36

def template
  @template ||=
    File.expand_path("templates/dummy_template.rb", __dir__)
end