Class: BaseProvision
- Inherits:
-
Object
- Object
- BaseProvision
- Includes:
- Executable, ScriptLocator
- Defined in:
- lib/script_executor/base_provision.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#interpolator ⇒ Object
readonly
Returns the value of attribute interpolator.
-
#script_list ⇒ Object
readonly
Returns the value of attribute script_list.
-
#server_info ⇒ Object
readonly
Returns the value of attribute server_info.
Instance Method Summary collapse
- #ask_password(message) ⇒ Object
- #create_script_methods ⇒ Object
- #create_thor_methods(parent_class) ⇒ Object
-
#initialize(parent_class, config_file_name, scripts_file_names) ⇒ BaseProvision
constructor
A new instance of BaseProvision.
- #read_config(config_file_name) ⇒ Object
- #run(script_name, params = {}, type = :string) ⇒ Object
Methods included from Executable
Methods included from ScriptLocator
#evaluate_script_body, #scripts
Constructor Details
#initialize(parent_class, config_file_name, scripts_file_names) ⇒ BaseProvision
Returns a new instance of BaseProvision.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/script_executor/base_provision.rb', line 13 def initialize parent_class, config_file_name, scripts_file_names @interpolator = TextInterpolator.new @env = read_config(config_file_name) @script_list = {} scripts_file_names.each do |name| @script_list.merge!(scripts(name)) end create_script_methods create_thor_methods(parent_class) if parent_class.ancestors.collect(&:to_s).include?('Thor') @server_info = env[:node] ? env[:node] : {} @terminal ||= HighLine.new end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
11 12 13 |
# File 'lib/script_executor/base_provision.rb', line 11 def env @env end |
#interpolator ⇒ Object (readonly)
Returns the value of attribute interpolator.
11 12 13 |
# File 'lib/script_executor/base_provision.rb', line 11 def interpolator @interpolator end |
#script_list ⇒ Object (readonly)
Returns the value of attribute script_list.
11 12 13 |
# File 'lib/script_executor/base_provision.rb', line 11 def script_list @script_list end |
#server_info ⇒ Object (readonly)
Returns the value of attribute server_info.
11 12 13 |
# File 'lib/script_executor/base_provision.rb', line 11 def server_info @server_info end |
Instance Method Details
#ask_password(message) ⇒ Object
39 40 41 |
# File 'lib/script_executor/base_provision.rb', line 39 def ask_password @terminal.ask() { |q| q.echo = "*" } end |
#create_script_methods ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/script_executor/base_provision.rb', line 53 def create_script_methods script_list.keys.each do |name| singleton_class.send(:define_method, name.to_sym) do self.run name.to_s, env end end end |
#create_thor_methods(parent_class) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/script_executor/base_provision.rb', line 61 def create_thor_methods parent_class provision = self provision.script_list.each do |name, value| title = value[:comment] title = title.nil? ? name : title parent_class.send(:desc, name, title) if parent_class.respond_to?(:desc) parent_class.send(:define_method, name.to_sym) do provision.send "#{name}".to_sym end end end |
#read_config(config_file_name) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/script_executor/base_provision.rb', line 43 def read_config config_file_name hash = JSON.parse(File.read(config_file_name), :symbolize_names => true) result = interpolator.interpolate hash puts interpolator.errors if interpolator.errors.size > 0 result end |
#run(script_name, params = {}, type = :string) ⇒ Object
33 34 35 36 37 |
# File 'lib/script_executor/base_provision.rb', line 33 def run script_name, params={}, type=:string execute(server_info) do evaluate_script_body(script_list[script_name.to_sym][:codeLines].join("\n"), params, type) end end |