Class: GlimContext
- Inherits:
-
Object
- Object
- GlimContext
- Defined in:
- lib/glim_context.rb
Instance Attribute Summary collapse
-
#log_name ⇒ Object
readonly
Returns the value of attribute log_name.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#template_subdir ⇒ Object
readonly
Returns the value of attribute template_subdir.
Instance Method Summary collapse
-
#initialize(log_name: nil, template_subdir: "templates") ⇒ GlimContext
constructor
A new instance of GlimContext.
- #log_base ⇒ Object
- #log_base_glim ⇒ Object
- #log_line_to_summary(line) ⇒ Object
- #request(args) ⇒ Object
- #request_from_template(template_name, **template_args) ⇒ Object
-
#response_from_template(template_name, **template_args) ⇒ Object
just for convenience.
Constructor Details
#initialize(log_name: nil, template_subdir: "templates") ⇒ GlimContext
Returns a new instance of GlimContext.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/glim_context.rb', line 8 def initialize(log_name: nil, template_subdir: "templates") #["test/test_glim.rb:71:in `new'", if !log_name @log_name = caller[0].split(':').first.split('/').last else @log_name = log_name end @log_name += Time.now.strftime('%Y-%m-%d-%H-%M-%S') @template_subdir = template_subdir.must_be_a String putt :log, "GlimContext template_subdir=#{@template_subdir}, log_name: #{log_name.inspect}" @start_time = Time.now end |
Instance Attribute Details
#log_name ⇒ Object (readonly)
Returns the value of attribute log_name.
5 6 7 |
# File 'lib/glim_context.rb', line 5 def log_name @log_name end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
6 7 8 |
# File 'lib/glim_context.rb', line 6 def start_time @start_time end |
#template_subdir ⇒ Object (readonly)
Returns the value of attribute template_subdir.
5 6 7 |
# File 'lib/glim_context.rb', line 5 def template_subdir @template_subdir end |
Instance Method Details
#log_base ⇒ Object
46 47 48 |
# File 'lib/glim_context.rb', line 46 def log_base File.join(log_base_glim,log_name) end |
#log_base_glim ⇒ Object
42 43 44 |
# File 'lib/glim_context.rb', line 42 def log_base_glim ENV['GLIM_LOG_DIRECTORY'] end |
#log_line_to_summary(line) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/glim_context.rb', line 50 def log_line_to_summary(line) log_summary_file = File.join(log_base, "llm_log.csv") seconds_since_start = Time.now - start_time s = "#{seconds_since_start.round(3)}, #{line}" File.open(log_summary_file, 'a') do |f| f.puts s end end |
#request(args) ⇒ Object
21 22 23 24 |
# File 'lib/glim_context.rb', line 21 def request(args) args_with_context = args.merge(context: self) GlimRequest.new(**args_with_context) end |
#request_from_template(template_name, **template_args) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/glim_context.rb', line 26 def request_from_template(template_name, **template_args) req = GlimRequest.new(context: self) req.process_template(template_name, **template_args) req.context = self req end |
#response_from_template(template_name, **template_args) ⇒ Object
just for convenience
34 35 36 37 38 39 40 |
# File 'lib/glim_context.rb', line 34 def response_from_template(template_name, **template_args) template_name.must_be_a String template_args.must_be_a Hash # puts("response_from_spec: #{template_args.inspect}") req = request_from_template(template_name, **template_args) req.response end |