Class: Apimaster::Generators::AppGenerator

Inherits:
Create show all
Defined in:
lib/apimaster/generators/app_generator.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_SHEBANG

Instance Attribute Summary collapse

Attributes inherited from Base

#active, #args, #destination_root, #logger, #source_root, #spec, #stdout

Attributes included from Options

#options

Instance Method Summary collapse

Methods inherited from Create

#class_collisions, #complex_template, #directory, #file, #file_copy_each, #folder, #identical?, #migration_template, #readme, #route_resources, #template, #template_copy_each, #write_manifest

Methods inherited from Command

#class_collisions, #dependency, #destination_path, #invoke!, #readme, #source_path, #write_manifest

Methods inherited from Base

#after_generate, #base_name, #camelize, #destination_path, #pluralize, #run, #source_path

Methods included from Options

included

Constructor Details

#initialize(runtime_args, runtime_options = {}) ⇒ AppGenerator

Returns a new instance of AppGenerator.



6
7
8
9
10
11
12
13
14
# File 'lib/apimaster/generators/app_generator.rb', line 6

def initialize(runtime_args, runtime_options = {})
  super
  #@destination_root = args.shift
  #@app_name     = File.basename(File.expand_path(@destination_root))
  @app_name     = args[0]
  raise 'Undefined app name.' unless @app_name
  @module_name  = camelize(app_name)
  extract_options
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



4
5
6
# File 'lib/apimaster/generators/app_generator.rb', line 4

def app_name
  @app_name
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



4
5
6
# File 'lib/apimaster/generators/app_generator.rb', line 4

def module_name
  @module_name
end

Instance Method Details

#manifestObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/apimaster/generators/app_generator.rb', line 16

def manifest
  record do |m|
    # Ensure appropriate folder(s) exists
    m.directory ''
    BASEDIRS.each { |path| m.directory(app_name + '/' + path) }
    m.directory "#{app_name}/lib/#{app_name}"

    # config
    templates = {
      "config/boot.rb.erb" => "config/boot.rb",
      "config/patches.rb.erb" => "config/patches.rb",
      "config/initializer.rb.erb" => "config/initializer.rb",
      "config/application.rb.erb" => "config/application.rb",
      "config/settings/mongoid.yml.erb" => "config/settings/mongoid.yml",
      "config/settings/app.yml.erb" => "config/settings/app.yml",
      "config/settings/oauth.yml.erb" => "config/settings/oauth.yml",

      # Create stubs
      "config.ru.erb" => "config.ru",
      "gitignore" => ".gitignore",
      "lib/module.rb.erb" => "lib/#{app_name}.rb",
      "app/tasks/test.rake.erb" => "app/tasks/test.rake",
      "app/tasks/stat.rake.erb" => "app/tasks/stat.rake",
      "app/controllers/index_controller.rb.erb" => "app/controllers/index_controller.rb",
      "app/controllers/befores_controller.rb.erb" => "app/controllers/befores_controller.rb",

      # Test stubs
      "test/test_helper.rb.erb" => "test/test_helper.rb"
    }.each { |k, v| m.template(k, app_name + '/' + v) }

    %w(LICENSE Rakefile README.md Gemfile TODO test.watchr).each do |file|
      m.template file, app_name + '/' + file
    end
  end
end