Class: EPM::Deploy
- Inherits:
-
Object
- Object
- EPM::Deploy
- Defined in:
- lib/epm/deploy.rb
Instance Method Summary collapse
- #deploy(command) ⇒ Object
- #deploy_package ⇒ Object
-
#initialize(def_file, settings = {}) ⇒ Deploy
constructor
A new instance of Deploy.
- #log(command) ⇒ Object
- #modify_deploy(command) ⇒ Object
- #query(command) ⇒ Object
- #set_var(command) ⇒ Object
- #transact(command) ⇒ Object
Constructor Details
#initialize(def_file, settings = {}) ⇒ Deploy
Returns a new instance of Deploy.
5 6 7 8 9 10 11 |
# File 'lib/epm/deploy.rb', line 5 def initialize def_file, settings={} @dirname = File.dirname(File.absolute_path(def_file)) @log_file = File.join(ENV['HOME'], '.epm', 'deployed-log.csv') @settings = settings @brain = {} @def_file = def_file end |
Instance Method Details
#deploy(command) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/epm/deploy.rb', line 44 def deploy command deploy_k = command.shift k_name = command.shift p "Deploying #{deploy_k} with name of #{k_name.gsub(/(\{|\})/,'')}." k_address = EPM::Create.new(File.join(@dirname, deploy_k), @settings).deploy @brain[k_name] = k_address p "#{k_name} => #{k_address}" end |
#deploy_package ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/epm/deploy.rb', line 13 def deploy_package if @def_file commands = File.readlines @def_file commands = commands.reject{|cmd| cmd[/\A#/] || cmd[/\A$/]}.map{|cmd| cmd.gsub("\n",'')} commands = commands.inject([]) do |arr,ele| ele[/\A\S+/] ? arr << [ele] : arr[-1] << ele.strip.split(' => ') arr end commands.each do |cmd| dowit = cmd.shift case dowit when 'deploy:' deploy cmd.shift sleep 1 when 'modify-deploy:' modify_deploy cmd sleep 1 when 'transact:' transact cmd.shift sleep 1 when 'query:' query cmd.shift when 'log:' log cmd.shift when 'set:' set_var cmd.shift end end end end |
#log(command) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/epm/deploy.rb', line 105 def log command address = command.shift name = command.shift until ! address[/(\{\{.*?\}\})/] address.gsub!($1,@brain[$1]) end until ! name[/(\{\{.*?\}\})/] name.gsub!($1,@brain[$1]) end log_entry = [address, name].join(',') p "Logging [#{address},#{name}]" `echo #{log_entry} >> #{@log_file}` end |
#modify_deploy(command) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/epm/deploy.rb', line 53 def modify_deploy command deploy_k = command[0].shift deploy_k = EPM::FileHelpers.file_guard(File.join(@dirname, deploy_k)) k_name = command[0].shift dump = command.shift until command.empty? cmd = command.shift to_replace = cmd.shift replacer = cmd.shift until ! replacer[/(\{\{.*?\}\})/] replacer.gsub!($1, @brain[$1]) end k_value = File.read deploy_k k_value = k_value.gsub "#{to_replace}", "#{replacer}" File.open(deploy_k, 'w'){|f| f.write k_value} end p "After modifying, am deploying #{deploy_k} with name of #{k_name.gsub(/(\{|\})/,'')}." k_address = EPM::Create.new(deploy_k, @settings).deploy @brain[k_name] = k_address p "#{k_name} => #{k_address}" end |
#query(command) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/epm/deploy.rb', line 89 def query command contract = command.shift address = command.shift name = command.shift until ! contract[/(\{\{.*?\}\})/] contract.gsub!($1,@brain[$1]) end until ! address[/(\{\{.*?\}\})/] address.gsub!($1,@brain[$1]) end p "Querying #{contract} at: #{address}." storage = EPM::Query.new(contract, address, @settings).query p "#{contract}:#{address} => #{storage}" @brain[name] = storage end |
#set_var(command) ⇒ Object
119 120 121 122 123 124 |
# File 'lib/epm/deploy.rb', line 119 def set_var command key = command.shift value = command.shift p "Setting #{key} to #{value}" @brain[key] = value end |
#transact(command) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/epm/deploy.rb', line 75 def transact command recipient = command.shift until ! recipient[/(\{\{.*?\}\})/] recipient.gsub!($1, @brain[$1]) end data = command.shift until ! data[/(\{\{.*?\}\})/] data.gsub!($1,@brain[$1]) end data = data.split(' ') p "Sending #{recipient} the data: #{data}." EPM::Transact.new(recipient, data, @settings).transact end |