Class: Jets::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/generator.rb

Overview

Piggy back off of Rails Generators.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(generator, *args) ⇒ Generator

Returns a new instance of Generator.



7
8
9
10
# File 'lib/jets/generator.rb', line 7

def initialize(generator, *args)
  @generator = generator
  @args = args
end

Class Method Details

.invoke(generator, *args) ⇒ Object



3
4
5
# File 'lib/jets/generator.rb', line 3

def self.invoke(generator, *args)
  new(generator, *args).invoke
end

Instance Method Details

#configObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jets/generator.rb', line 20

def config
  g = Rails::Configuration::Generators.new
  g.orm             :active_record, migration: true, timestamps: true
  # TODO: support g.orm :dynamodb
  g.template_engine :erb
  g.test_framework  false #:test_unit, fixture: false
  # g.test_framework :rspec # need to
  # TODO: load rspec configuration to use rspec
  g.stylesheets     false
  g.javascripts     false
  g.assets          false
  g.api             Jets.config.mode == 'api'
  g.resource_route  true
  g.templates.unshift(template_paths)
  g
end

#invokeObject



12
13
14
15
16
17
18
# File 'lib/jets/generator.rb', line 12

def invoke
  # lazy require so Rails const is only defined when using generators
  require "rails/generators"
  require "rails/configuration"
  Rails::Generators.configure!(config)
  Rails::Generators.invoke(@generator, @args, behavior: :invoke, destination_root: Jets.root)
end

#template_pathsObject



37
38
39
40
# File 'lib/jets/generator.rb', line 37

def template_paths
  templates_path = File.expand_path("../generator/templates", __FILE__)
  [templates_path]
end