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.
36 37 38 |
# File 'lib/brute/prompts/base.rb', line 36 def initialize(ctx) @ctx = ctx end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/brute/prompts/base.rb', line 40 def method_missing(name, *args) if args.empty? && @ctx.key?(name) @ctx[name] else super end end |
Instance Method Details
#escape_xml(value) ⇒ Object Also known as: h
XML-escape a value for prompt markup (& < > " ').
53 54 55 56 |
# File 'lib/brute/prompts/base.rb', line 53 def escape_xml(value) value.to_s.gsub("&", "&").gsub("<", "<").gsub(">", ">") .gsub('"', """).gsub("'", "'") end |
#get_binding ⇒ Object
59 60 61 |
# File 'lib/brute/prompts/base.rb', line 59 def get_binding binding end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
48 49 50 |
# File 'lib/brute/prompts/base.rb', line 48 def respond_to_missing?(name, include_private = false) @ctx.key?(name) || super end |