Class: Luogu::Plugin

Inherits:
Object
  • Object
show all
Defined in:
lib/luogu/plugin.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plugin_file_path) ⇒ Plugin

Returns a new instance of Plugin.



13
14
15
# File 'lib/luogu/plugin.rb', line 13

def initialize(plugin_file_path)
  @plugin_file_path = plugin_file_path
end

Instance Attribute Details

#after_input_procObject (readonly)

Returns the value of attribute after_input_proc.



3
4
5
# File 'lib/luogu/plugin.rb', line 3

def after_input_proc
  @after_input_proc
end

#after_request_procObject (readonly)

Returns the value of attribute after_request_proc.



3
4
5
# File 'lib/luogu/plugin.rb', line 3

def after_request_proc
  @after_request_proc
end

#after_save_history_procObject (readonly)

Returns the value of attribute after_save_history_proc.



3
4
5
# File 'lib/luogu/plugin.rb', line 3

def after_save_history_proc
  @after_save_history_proc
end

#before_input_procObject (readonly)

Returns the value of attribute before_input_proc.



3
4
5
# File 'lib/luogu/plugin.rb', line 3

def before_input_proc
  @before_input_proc
end

#before_request_procObject (readonly)

Returns the value of attribute before_request_proc.



3
4
5
# File 'lib/luogu/plugin.rb', line 3

def before_request_proc
  @before_request_proc
end

#before_save_history_procObject (readonly)

Returns the value of attribute before_save_history_proc.



3
4
5
# File 'lib/luogu/plugin.rb', line 3

def before_save_history_proc
  @before_save_history_proc
end

#plugin_file_pathObject (readonly)

Returns the value of attribute plugin_file_path.



3
4
5
# File 'lib/luogu/plugin.rb', line 3

def plugin_file_path
  @plugin_file_path
end

#setup_procObject (readonly)

Returns the value of attribute setup_proc.



3
4
5
# File 'lib/luogu/plugin.rb', line 3

def setup_proc
  @setup_proc
end

Class Method Details

.define_attr_setter(attr_name) ⇒ Object

定义一个元编程方法来动态定义属性设置方法



7
8
9
10
11
# File 'lib/luogu/plugin.rb', line 7

def self.define_attr_setter(attr_name)
  define_method("#{attr_name}") do |&block|
    instance_variable_set("@#{attr_name}_proc", block)
  end
end

Instance Method Details

#loadObject



26
27
28
29
# File 'lib/luogu/plugin.rb', line 26

def load()
  self.instance_eval File.read(plugin_file_path)
  self
end

#run(method_name: nil, llm: nil, context: nil, &block) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/luogu/plugin.rb', line 31

def run(method_name: nil, llm: nil, context: nil, &block)
  method_name = "#{method_name}_proc".to_sym
  if send(method_name).respond_to?(:call)
    rt = send(method_name).call(llm, context)
    block.call(rt) unless block.nil?
    rt
  end
end