examples/simple.rb in prompt_manager-0.1.1 vs examples/simple.rb in prompt_manager-0.2.0

- old
+ new

@@ -7,12 +7,14 @@ ## File: simple.rb ## Desc: Simple demo of the PromptManager and FileStorageAdapter ## By: Dewayne VanHoozer (dvanhoozer@gmail.com) ## # +# TODO: Add `list` to get an Array of prompt IDs +# TODO: Add `path` to get a path to the prompt file +# - require 'prompt_manager' require 'prompt_manager/storage/file_system_adapter' require 'amazing_print' require 'pathname' @@ -29,15 +31,18 @@ puts "Done." puts end # Configure the Storage Adapter to use +PromptManager::Storage::FileSystemAdapter.config do |config| + config.prompts_dir = PROMPTS_DIR + # config.search_proc = nil # default + # config.prompt_extension = '.txt' # default + # config.parms+_extension = '.json' # default +end -PromptManager::Prompt.storage_adapter = - PromptManager::Storage::FileSystemAdapter.new( - prompts_dir: PROMPTS_DIR - ) +PromptManager::Prompt.storage_adapter = PromptManager::Storage::FileSystemAdapter.new # Get a prompt todo = PromptManager::Prompt.get(id: 'todo') @@ -85,5 +90,53 @@ ============================== EOS puts todo.to_s +puts <<~EOS + + When using the FileSystemAdapter for prompt storage you can have within + the prompts_dir you can have many sub-directories. These sub-directories + act like categories. The prompt ID is composed for the sub-directory name, + a "/" character and then the normal prompt ID. For example "toy/8-ball" + +EOS + +magic = PromptManager::Prompt.get( id: 'toy/8-ball' ) + +puts "The magic PROMPT is:" +puts magic +puts +puts "Remember if you want to see the full text of the prompt file:" +puts magic.text + +puts "="*64 + +puts <<~EOS + + The FileSystemAdapter also adds two new methods to the Prompt class: + + list - provides an Array of pompt IDs + path(prompt_id) - Returns a Pathname object to the prompt file + +EOS + +puts "List of prompts available" +puts "=========================" + +puts PromptManager::Prompt.list + +puts <<~EOS + + And the path to the "toy/8-ball" prompt file is: + + #{magic.path} + + Use "your_prompt.path" for when you want to do something with the + the prompt file like send it to a text editor. + + Your can also use the class method if you supply a prompt_id + like this: + +EOS + +puts PromptManager::Prompt.path('toy/8-ball')