Class: ActionPrompt::ActionPromptGenerator

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

Overview

Rails generator that creates a prompt class and its ERB view templates.

Usage

rails generate action_prompt NAME [action action ...]

Examples

rails generate action_prompt ArticleSummarizer summarize
rails generate action_prompt Moderation classify flag
rails generate action_prompt Admin::Report generate

Each invocation creates:

* app/prompts/<name>_prompt.rb
* app/views/action_prompts/<name>_prompt/<action>.text.erb  (one per action)

Instance Method Summary collapse

Instance Method Details

#create_prompt_fileObject

------------------------------------------------------------------ # Steps ------------------------------------------------------------------ #



36
37
38
39
# File 'lib/generators/action_prompt/action_prompt_generator.rb', line 36

def create_prompt_file
  template "prompt.rb.tt",
           File.join("app/prompts", class_path, "#{file_name}_prompt.rb")
end

#create_view_filesObject



41
42
43
44
45
46
47
48
# File 'lib/generators/action_prompt/action_prompt_generator.rb', line 41

def create_view_files
  actions.each do |action|
    @current_action = action
    template "prompt.text.erb.tt",
             File.join("app/views/action_prompts", class_path,
                       "#{file_name}_prompt", "#{action}.text.erb")
  end
end