Class: Brute::Prompts::Context

Inherits:
Object
  • Object
show all
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

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("&", "&amp;").gsub("<", "&lt;").gsub(">", "&gt;")
     .gsub('"', "&quot;").gsub("'", "&apos;")
end

#get_bindingObject



52
53
54
# File 'lib/brute/prompts/base.rb', line 52

def get_binding
  binding
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (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