Class: MotorheadGenerator

Inherits:
Rails::Generators::PluginGenerator
  • Object
show all
Defined in:
lib/generators/motorhead_generator.rb

Defined Under Namespace

Classes: EngineBuilder

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ MotorheadGenerator

Returns a new instance of MotorheadGenerator.



19
20
21
22
23
24
25
26
# File 'lib/generators/motorhead_generator.rb', line 19

def initialize(*args)
  options = args.extract_options!
  options[:destination_root] = 'app/engines'
  super(*args, options)
  options = @options.dup
  options[:mountable] = options[:skip_bundle] = options[:skip_test_unit] = options[:skip_git] = options[:skip_gemfile] = true
  @options = options.freeze
end

Class Method Details

.source_pathsObject



14
15
16
# File 'lib/generators/motorhead_generator.rb', line 14

def source_paths
  [File.expand_path('../motorhead/templates', __FILE__), *super]
end

Instance Method Details

#bundle_to_parentObject



47
48
49
50
# File 'lib/generators/motorhead_generator.rb', line 47

def bundle_to_parent
  gemfile = Rails.root + 'Gemfile'
  append_to_file gemfile, "gem '#{name}', path: '#{destination_root.sub(%r(^#{Rails.root}/), '')}'\n" if gemfile.exist?
end

#create_bin_filesObject

override



33
34
# File 'lib/generators/motorhead_generator.rb', line 33

def create_bin_files
end

#generate_controllerObject



52
53
54
55
56
57
58
59
# File 'lib/generators/motorhead_generator.rb', line 52

def generate_controller
  if base_controller
    Dir.chdir destination_root do
      #FIXME call the controller generator directly
      puts `rails g motorhead:controller #{name}/#{base_controller} #{actions * ' '}`
    end
  end
end

#get_builder_classObject



28
29
30
# File 'lib/generators/motorhead_generator.rb', line 28

def get_builder_class
  EngineBuilder
end

#put_litter_in_its_placeObject



36
37
38
39
40
# File 'lib/generators/motorhead_generator.rb', line 36

def put_litter_in_its_place
  remove_file 'MIT-LICENSE'
  remove_file "app/controllers/#{name}/application_controller.rb"
  remove_file "lib/tasks"
end

#untodo_gemspecObject



42
43
44
45
# File 'lib/generators/motorhead_generator.rb', line 42

def untodo_gemspec
  gemspec = "#{name}.gemspec"
  gsub_file gemspec, /"TODO.*?"/, '""'
end