Module: ActiveRecord::Acts::ShellscriptExecutable::ClassMethods

Defined in:
lib/acts_as_shellscript_executable/active_record/acts/shellscript_executable.rb

Instance Method Summary collapse

Instance Method Details

#__add_method(type, method: nil, script: :script, command: nil) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/acts_as_shellscript_executable/active_record/acts/shellscript_executable.rb', line 41

def __add_method(type, method: nil, script: :script, command: nil)
  method ||= (type == :ruby ? :ruby_execute! : :execute!)
  command ||= (type == :ruby ? 'ruby' : '/bin/sh')
  __define_execute_method method, type
  __configs_set command, script, method
  include ::ActiveRecord::Acts::ShellscriptExecutable::InstanceMethods
end

#__configs_set(command, script, method) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/acts_as_shellscript_executable/active_record/acts/shellscript_executable.rb', line 23

def __configs_set(command, script, method)
  configurations = begin
                     class_variable_get(:@@__executable_methods__)
                   rescue NameError
                     {}
                   end
  configurations[method] = { command: command, script: script }
  class_variable_set(:@@__executable_methods__, configurations)
end

#__define_execute_method(method, type) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/acts_as_shellscript_executable/active_record/acts/shellscript_executable.rb', line 11

def __define_execute_method(method, type)
  class_eval "    def \#{method}(&block)\n      script = @@__executable_methods__[:\#{method}][:script]\n      command  = @@__executable_methods__[:\#{method}][:command]\n      answer = ''\n      __execute__(script, :\#{type}, answer, command, block)\n      block_given? ? nil : answer\n    end\n  EOV\nend\n"

#acts_as_rubyscript_executable(opt) ⇒ Object



37
38
39
# File 'lib/acts_as_shellscript_executable/active_record/acts/shellscript_executable.rb', line 37

def acts_as_rubyscript_executable(opt)
  __add_method(:ruby, opt)
end

#acts_as_shellscript_executable(opt) ⇒ Object



33
34
35
# File 'lib/acts_as_shellscript_executable/active_record/acts/shellscript_executable.rb', line 33

def acts_as_shellscript_executable(opt)
  __add_method(:shell, opt)
end