class Antimony::Formula
Constants
- FORMULAS_PATH
- LOG_PARENT_PATH
- LOG_PATH
Attributes
formula_log[RW]
inputs[RW]
outputs[RW]
Public Class Methods
new(name, inputs = {})
click to toggle source
# File lib/antimony/formula.rb, line 10 def initialize(name, inputs = {}) ($LOAD_PATH.unshift FORMULAS_PATH) unless $LOAD_PATH.include? FORMULAS_PATH @inputs = indifferent_hash(inputs) @outputs = {} init_log(name) helper_path = "#{FORMULAS_PATH}/formula_helper.rb" eval File.read(helper_path) if File.exist?(helper_path) # rubocop:disable Lint/Eval @formula = File.read("#{FORMULAS_PATH}/#{name}.rb") end
Public Instance Methods
run()
click to toggle source
# File lib/antimony/formula.rb, line 25 def run eval(@formula) # rubocop:disable Lint/Eval end
session(host, username, password) { || ... }
click to toggle source
# File lib/antimony/formula.rb, line 29 def session(host, username, password) @connection = Antimony::Session.new(host, username, password) yield if block_given? @log.info @connection.session_log @connection.close @connection = nil end
Private Instance Methods
indifferent_hash(hash)
click to toggle source
# File lib/antimony/formula.rb, line 53 def indifferent_hash(hash) {}.tap do |new_hash| hash.each do |key, value| value = indifferent_hash(value) if value.is_a?(Hash) new_hash[key.to_sym] = value new_hash[key.to_s] = value end end end
init_log(name)
click to toggle source
# File lib/antimony/formula.rb, line 39 def init_log(name) Dir.mkdir LOG_PARENT_PATH unless Dir.exist? LOG_PARENT_PATH Dir.mkdir LOG_PATH unless Dir.exist? LOG_PATH @log = Logging.logger[name] layout = Logging.layouts.pattern(pattern: "%m\n") @log.add_appenders(Logging.appenders.file("#{LOG_PATH}/#{name}.log", truncate: true, layout: layout)) end
method_missing(name, *args, &block)
click to toggle source
# File lib/antimony/formula.rb, line 48 def method_missing(name, *args, &block) raise 'No active connection!' unless @connection @connection.send(name, *args, &block) end