Class: MnoEnterprise::DummyGenerator

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

Constant Summary collapse

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

#databaseObject (readonly)

Returns the value of attribute database.



72
73
74
# File 'lib/generators/mno_enterprise/dummy/dummy_generator.rb', line 72

def database
  @database
end

#lib_nameObject (readonly)

Returns the value of attribute lib_name.



71
72
73
# File 'lib/generators/mno_enterprise/dummy/dummy_generator.rb', line 71

def lib_name
  @lib_name
end

Class Method Details

.source_pathsObject



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

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

Instance Method Details

#clean_upObject



17
18
19
# File 'lib/generators/mno_enterprise/dummy/dummy_generator.rb', line 17

def clean_up
  remove_directory_if_exists(dummy_path)
end

#generate_test_dummyObject



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

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

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

#test_dummy_cleanObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/generators/mno_enterprise/dummy/dummy_generator.rb', line 56

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 "public/index.html"
    remove_file "public/robots.txt"
    remove_file "README"
    remove_file "test"
    remove_file "vendor"
  end
end

#test_dummy_configObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/mno_enterprise/dummy/dummy_generator.rb', line 38

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.erb", "#{dummy_path}/config/boot.rb", force: true
  template "rails/application.rb.erb", "#{dummy_path}/config/application.rb", force: true
  template "rails/routes.rb", "#{dummy_path}/config/routes.rb", force: true
  template "rails/test-env.rb", "#{dummy_path}/config/environments/test.rb", force: true
end

#test_dummy_frontendObject

Overwrite mnoe less file required by asset pipeline



50
51
52
53
54
# File 'lib/generators/mno_enterprise/dummy/dummy_generator.rb', line 50

def test_dummy_frontend
  if defined?(MnoEnterprise::Frontend)
    create_file("#{dummy_path}/app/assets/stylesheets/main.less", force: true)
  end
end