Class: WagnGenerator

Inherits:
Rails::Generators::AppBase
  • Object
show all
Defined in:
lib/wagn/generators/wagn/wagn_generator.rb,
lib/wagn/generators/wagn/wagn_generator/interactive.rb

Defined Under Namespace

Classes: Interactive

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details



153
154
155
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 153

def self.banner
  "wagn new #{arguments.map(&:usage).join(' ')} [options]"
end

Instance Method Details

#configObject



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 93

def config
  empty_directory "config"

  inside "config" do
    template "application.rb"
    template "routes.erb", "routes.rb"
    template "environment.rb"
    template "boot.rb"
    template "databases/#{options[:database]}.yml", "database.yml"
    template "cucumber.yml" if options["core-dev"]
  end
end

#configruObject



85
86
87
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 85

def configru
  template "config.ru"
end

#database_gemfile_entryObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 138

def database_gemfile_entry
  return [] if options[:skip_active_record]
  gem_name, gem_version = gem_for_database
  if gem_name == "mysql2"
    # && Gem.loaded_specs['rails'].version < Gem::Version.new('4.2.5')
    # Rails update from 4.2.4 to 4.2.5 didn't help.
    # Current mysql2 gem (0.4.1) is still causing trouble.
    # Maybe with the next Rails release?
    # Could also be that ruby 1.9.3 is the problem.
    gem_version = "0.3.20"
  end
  msg = "Use #{options[:database]} as the database for Active Record"
  GemfileEntry.version gem_name, gem_version, msg
end

#dev_setupObject

should probably eventually use rails-like AppBuilder approach, but this is a first step.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 37

def dev_setup
  # TODO: rename or split, gem_path points to the source repo,
  # card and wagn gems are subdirs
  @gemfile_gem_path = @gem_path = options["gem-path"]
  env_gem_path = ENV["WAGN_GEM_PATH"]
  if env_gem_path.present?
    @gemfile_gem_path = %q(#{ENV['WAGN_GEM_PATH']})
    @gem_path = env_gem_path
  end

  @include_jasmine_engine = false
  if options["core-dev"]
    core_dev_setup
    shared_dev_setup
  elsif options["mod-dev"]
    mod_dev_setup
    shared_dev_setup
  end
end

#filesObject



73
74
75
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 73

def files
  empty_directory_with_keep_file "files"
end

#gemfileObject



81
82
83
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 81

def gemfile
  template "Gemfile"
end

#gitignoreObject



89
90
91
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 89

def gitignore
  copy_file "gitignore", ".gitignore"
end

#logObject



69
70
71
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 69

def log
  empty_directory_with_keep_file "log"
end

#modObject

def readme

  copy_file "README", "README.rdoc"
end


65
66
67
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 65

def mod
  empty_directory_with_keep_file "mod"
end

#publicObject



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 106

def public
  empty_directory "public"

  inside "public" do
    template "robots.txt"
    empty_directory "files"

    inside "files" do
      template "htaccess", ".htaccess"
    end
  end
end

#rakefileObject



57
58
59
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 57

def rakefile
  template "Rakefile"
end

#scriptObject



119
120
121
122
123
124
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 119

def script
  directory "script" do |content|
    "#{shebang}\n" + content
  end
  chmod "script", 0755 & ~File.umask, verbose: false
end

#seed_dataObject



128
129
130
131
132
133
134
135
136
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 128

def seed_data
  if options["interactive"]
    Interactive.new(options, destination_root).run
  else
    puts "Now:
1. Run `wagn seed` to seed your database (see db configuration in config/database.yml).
2. Run `wagn server` to start your server"
  end
end

#tmpObject



77
78
79
# File 'lib/wagn/generators/wagn/wagn_generator.rb', line 77

def tmp
  empty_directory "tmp"
end