Class: Brute::Prompts::Context
- Inherits:
-
Object
- Object
- Brute::Prompts::Context
- Defined in:
- lib/brute/prompts/base.rb
Overview
Template context handed to ERB templates. Context-hash keys become
methods (<%= skills %>, <%= cwd %>), plus view helpers like h.
Instance Method Summary collapse
-
#escape_xml(value) ⇒ Object
(also: #h)
XML-escape a value for prompt markup (& < > " ').
- #get_binding ⇒ Object
-
#initialize(ctx) ⇒ Context
constructor
A new instance of Context.
- #method_missing(name, *args) ⇒ Object
- #respond_to_missing?(name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(ctx) ⇒ Context
Returns a new instance of Context.
31 32 33 |
# File 'lib/brute/prompts/base.rb', line 31 def initialize(ctx) @ctx = ctx end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
35 36 37 38 39 |
# File 'lib/brute/prompts/base.rb', line 35 def method_missing(name, *args) return @ctx[name] if args.empty? && @ctx.key?(name) super end |
Instance Method Details
#escape_xml(value) ⇒ Object Also known as: h
XML-escape a value for prompt markup (& < > " ').
46 47 48 49 |
# File 'lib/brute/prompts/base.rb', line 46 def escape_xml(value) value.to_s.gsub("&", "&").gsub("<", "<").gsub(">", ">") .gsub('"', """).gsub("'", "'") end |
#get_binding ⇒ Object
52 53 54 |
# File 'lib/brute/prompts/base.rb', line 52 def get_binding binding end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
41 42 43 |
# File 'lib/brute/prompts/base.rb', line 41 def respond_to_missing?(name, include_private = false) @ctx.key?(name) || super end |