Class: SteroidGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/steroid/steroid_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_entry_in_steroids_listObject



44
45
46
47
# File 'lib/generators/steroid/steroid_generator.rb', line 44

def create_entry_in_steroids_list
  insert_into_file 'lib/rails_steroids/cli.rb', "  '#{name}',\n      ", after: "steroid_names = [\n      "
  insert_into_file 'README.md', "|#{name}|`rails_steroids inject steroid:#{name}`|\n", after: "|---|---|\n"
end

#create_steroid_generator_fileObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/steroid/steroid_generator.rb', line 3

def create_steroid_generator_file
  say "Preparing steroid for #{name.titlecase}", :green
  create_file "lib/generators/steroid/#{name}/#{name}_generator.rb", <<~RUBY
    # frozen_string_literal: true

    require 'tty/prompt'

    module Steroid
      class #{name.camelize}Generator < Rails::Generators::Base
        desc "Adds #{name.titlecase} to the application"
        source_root File.expand_path("templates", __dir__)

        def add_#{name}
          say "Applying steroid: #{name.titlecase}", [:bold, :magenta]
          # Add your other code here or any additional methods below this method
        end
      end
    end
  RUBY
end

#create_steroid_templates_directoryObject



24
25
26
# File 'lib/generators/steroid/steroid_generator.rb', line 24

def create_steroid_templates_directory
  empty_directory("lib/generators/steroid/#{name}/templates")
end

#create_usage_fileObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/generators/steroid/steroid_generator.rb', line 28

def create_usage_file
  create_file "lib/generators/steroid/#{name}/USAGE", <<~RUBY
    Description:
        `steroid:#{name}` will inject #{name.titlecase} functionality interactively.

    Usage Example:
        # with installed gem
        rails_steroids inject steroid:#{name}
        # with bundler
        bin/rails g steroid:#{name}

    What will this do?:
        what/will/it/create
  RUBY
end