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.



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

#get_bindingObject



59
60
61
# File 'lib/brute/prompts/base.rb', line 59

def get_binding
  binding
end

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

Returns:

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