Class: Charyf::Generators::AppBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/charyf/utils/generators/app/app_generator.rb

Overview

The application builder allows you to override elements of the application generator without being forced to reverse the operations of the default generator.

This allows you to override entire operations, like the creation of the Gemfile, README, or JavaScript files, without needing to know exactly what those operations do so you can create another template action.

class CustomAppBuilder < Charyf::Generators::AppBuilder def test @generator.gem "rspec", group: [:development, :test] run "bundle install" generate "rspec:install" end end

Instance Method Summary collapse

Instance Method Details

#app ⇒ Object



61
62
63
64
65
# File 'lib/charyf/utils/generators/app/app_generator.rb', line 61

def app
  directory "app"

  empty_directory_with_keep_file "app/skills"
end

#bin ⇒ Object



67
68
69
70
71
72
73
# File 'lib/charyf/utils/generators/app/app_generator.rb', line 67

def bin
  directory "bin" do |content|
    "#{shebang}\n" + content
  end

  chmod "bin", 0755 & ~File.umask, verbose: false
end

#config ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/charyf/utils/generators/app/app_generator.rb', line 75

def config
  empty_directory "config"

  inside "config" do
    template "application.rb"
    template "boot.rb"
    template "chapp.rb"
    template "load.rb"
    template "routes.rb"

    directory "environments"
    empty_directory_with_keep_file "initializers"
  end
end

#gemfile ⇒ Object



32
33
34
# File 'lib/charyf/utils/generators/app/app_generator.rb', line 32

def gemfile
  template 'Gemfile.erb', 'Gemfile'
end

#gitignore ⇒ Object



51
52
53
# File 'lib/charyf/utils/generators/app/app_generator.rb', line 51

def gitignore
  template 'gitignore', '.gitignore'
end

#lib ⇒ Object



90
91
92
# File 'lib/charyf/utils/generators/app/app_generator.rb', line 90

def lib
  empty_directory "lib"
end

#log ⇒ Object



94
95
96
# File 'lib/charyf/utils/generators/app/app_generator.rb', line 94

def log
  empty_directory_with_keep_file "log"
end

#readme ⇒ Object

def rakefile template "Rakefile" end



28
29
30
# File 'lib/charyf/utils/generators/app/app_generator.rb', line 28

def readme
  copy_file 'README.md', 'README.md'
end

#tmp ⇒ Object



98
99
100
# File 'lib/charyf/utils/generators/app/app_generator.rb', line 98

def tmp
  empty_directory_with_keep_file "tmp"
end

#update_gemfile ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/charyf/utils/generators/app/app_generator.rb', line 36

def update_gemfile

  gemfile_entries.each do |entry|
    options = entry.options.dup
    options[:comment] = entry.comment if entry.comment && !entry.comment.empty?

    versions = entry.version ? entry.version.split(", ") : nil

    args = [entry.name, versions, options].flatten.compact

    @generator.gem *args
  end

end

#version_control ⇒ Object



55
56
57
58
59
# File 'lib/charyf/utils/generators/app/app_generator.rb', line 55

def version_control
  if !options[:skip_git] && !options[:pretend]
    run "git init", capture: options[:quiet]
  end
end