Class: LLMed::Context
- Inherits:
-
Object
- Object
- LLMed::Context
- Defined in:
- lib/llmed/context.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #digest ⇒ Object
-
#from_erb(path) ⇒ Object
Example: context(“application”) { from_erb(“application.cllmed.erb”) }.
-
#from_file(path) ⇒ Object
Example: context(“application”) { from_file(“application.cllmed”) }.
-
#from_release(path) ⇒ Object
Example: context(“source”) { from_release(“file in release dir”) }.
-
#from_source_code(path) ⇒ Object
Example: context(“source”) { from_source_code(“sourcepathtoinclude”) }.
-
#initialize(name:, digest: nil, options: {}) ⇒ Context
constructor
A new instance of Context.
- #llm(message) ⇒ Object
- #message ⇒ Object
- #message? ⇒ Boolean
- #raw ⇒ Object
- #same_digest?(val) ⇒ Boolean
-
#sh(cmd) ⇒ Object
Example: context(“files”) { sh “ls /etc” }.
- #skip? ⇒ Boolean
Constructor Details
#initialize(name:, digest: nil, options: {}) ⇒ Context
Returns a new instance of Context.
47 48 49 50 51 52 |
# File 'lib/llmed/context.rb', line 47 def initialize(name:, digest: nil, options: {}) @name = name @skip = [:skip] || false @fixed_digest = digest || nil @release_dir = [:release_dir] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
45 46 47 |
# File 'lib/llmed/context.rb', line 45 def name @name end |
Instance Method Details
#digest ⇒ Object
62 63 64 |
# File 'lib/llmed/context.rb', line 62 def digest @fixed_digest || Digest::SHA256.hexdigest("#{@name}.#{@message}") end |
#from_erb(path) ⇒ Object
Example:
context("application") { from_erb("application.cllmed.erb") }
96 97 98 |
# File 'lib/llmed/context.rb', line 96 def from_erb(path) ERB.new(File.read(path)).result(binding) end |
#from_file(path) ⇒ Object
Example:
context("application") { from_file("application.cllmed") }
90 91 92 |
# File 'lib/llmed/context.rb', line 90 def from_file(path) File.read(path) end |
#from_release(path) ⇒ Object
Example:
context("source") { from_release("file in release dir") }
109 110 111 112 |
# File 'lib/llmed/context.rb', line 109 def from_release(path) code = File.read(Pathname.new(@release_dir) + path) " Given the following source code: #{code}\n\n\n" end |
#from_source_code(path) ⇒ Object
Example:
context("source") { from_source_code("sourcepathtoinclude") }
102 103 104 105 |
# File 'lib/llmed/context.rb', line 102 def from_source_code(path) code = File.read(path) " Given the following source code: #{code}\n\n\n" end |
#llm(message) ⇒ Object
74 75 76 |
# File 'lib/llmed/context.rb', line 74 def llm() = end |
#message ⇒ Object
66 67 68 |
# File 'lib/llmed/context.rb', line 66 def "# Context: \"#{@name}\" Digest: #{digest}\n\n#{@message}" end |
#message? ⇒ Boolean
78 79 80 |
# File 'lib/llmed/context.rb', line 78 def !(.nil? || .empty?) end |
#raw ⇒ Object
70 71 72 |
# File 'lib/llmed/context.rb', line 70 def raw end |
#same_digest?(val) ⇒ Boolean
58 59 60 |
# File 'lib/llmed/context.rb', line 58 def same_digest?(val) digest == val end |
#sh(cmd) ⇒ Object
Example:
context("files") { sh "ls /etc" }
84 85 86 |
# File 'lib/llmed/context.rb', line 84 def sh(cmd) `#{cmd}` end |
#skip? ⇒ Boolean
54 55 56 |
# File 'lib/llmed/context.rb', line 54 def skip? @skip end |