Module: Waxx::Console::Command

Extended by:
Command
Included in:
Command
Defined in:
waxx/console.rb

Overview

Handle console commands. These are called on the command line: waxx on, waxx deploy prod, waxx test app, etc.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x



73
74
75
# File 'waxx/console.rb', line 73

def x
  @x
end

Instance Method Details

#config(opts) ⇒ Object



134
135
136
# File 'waxx/console.rb', line 134

def config(opts)
  puts Waxx.data.send("to_#{opts[:format]}")
end

#console(opts) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'waxx/console.rb', line 110

def console(opts)
  if File.exist? 'app/app.rb'
    require 'irb'
    puts "waxx console"
    #help = "Use the source, Luke"
    begin
      x = Waxx::Console.x
      binding.irb
    rescue
      IRB.setup(nil)
      workspace = IRB::WorkSpace.new(self)
      irb = IRB::Irb.new(workspace)
      IRB.conf[:MAIN_CONTEXT] = irb.context
      irb.eval_input
      require 'lib/waxx/irb.rb'
      @x = Waxx::Console.x
      IRB.start_session(self) #"#{opts[:base]}/lib/waxx/irb_env.rb")
    end
  else
    puts "Error: You need to call 'waxx console' from the root of a waxx installation."
    exit 1
  end
end

#delete(opts) ⇒ Object



106
107
108
# File 'waxx/console.rb', line 106

def delete(opts)
  App.delete(ARGV[1], opts)
end

#deploy(target, opts) ⇒ Object



138
139
140
141
142
143
144
# File 'waxx/console.rb', line 138

def deploy(target, opts)
  dep = YAML.load_file("#{opts[:base]}/opt/deploy.yaml")
  dep[target.to_s].each{|n,v|
    puts "Deploying #{target} to #{n}"
    `ssh #{v['user']}@#{v['host']} '#{v['command']}'`
  }
end

#get(url = ARGV[1], opts = {}) ⇒ Object



93
94
95
96
# File 'waxx/console.rb', line 93

def get(url=ARGV[1], opts={})
  Waxx['debug']['level'] = 0
  Waxx::Console.get(url, opts)
end

#init(opts) ⇒ Object



146
147
148
149
# File 'waxx/console.rb', line 146

def init(opts)
  require_relative 'init'
  Waxx::Init.init(x, opts)
end

#migrate(db = 'app', opts = {}) ⇒ Object



151
152
153
# File 'waxx/console.rb', line 151

def migrate(db='app', opts={})
  Waxx::Database.migrate db, opts
end

#migration(db = 'app', name = nil, opts = {}) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'waxx/console.rb', line 155

def migration(db='app', name=nil, opts={})
  dt = Time.new.strftime('%Y%m%d%H%M')
  if name.nil?
    puts "Enter the name of the migration: "
    name = gets.chomp
  end           
  m_file = "db/#{db}/#{dt}-#{name.gsub(/\W/,"-")}.sql"
  File.open(m_file, "w"){|f|
    f.puts "BEGIN;\n\n\n\nCOMMIT;"
  }
  puts "Created #{m_file}"
  system "/usr/bin/env #{ENV['EDITOR'] || 'vim'} #{m_file}"
end

#off(opts) ⇒ Object Also known as: stop



81
82
83
# File 'waxx/console.rb', line 81

def off(opts)
  Waxx::Process::Runner.new('waxx').execute(kill: true, pid_path: opts[:pid_path])
end

#on(opts) ⇒ Object Also known as: start



74
75
76
77
78
# File 'waxx/console.rb', line 74

def on(opts)
  Waxx::Process::Runner.new('waxx').execute(daemonize: true, pid_path: opts[:pid_path], log_path: opts[:log_path]){
    ::App.start(opts)
  }
end

#post(opts) ⇒ Object



98
99
100
# File 'waxx/console.rb', line 98

def post(opts)
  App.post(ARGV[1], opts)
end

#put(opts) ⇒ Object



102
103
104
# File 'waxx/console.rb', line 102

def put(opts)
  App.put(ARGV[1], opts)
end

#restart(opts) ⇒ Object Also known as: buff



86
87
88
89
90
# File 'waxx/console.rb', line 86

def restart(opts)
  stop opts
  sleep 1
  start opts
end

#test(target, opts) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'waxx/console.rb', line 169

def test(target, opts)
  require_relative 'test'
  start_time = Time.new
  re = {}
  total_tests = 0
  total_passed = 0
  if target == "waxx"
    tests = []
    Dir.entries(opts[:base] + '/test').each{|f|
      next if f =~ /^\./
      tests << f.sub(/\.rb$/,"")
      path = opts[:base] + '/test/' + f
      puts path
      require path
    }

    tests.each{|waxx_module_test|
      re[waxx_module_test] = Waxx.send(waxx_module_test)
      re[waxx_module_test].each{|file, mod| 
        mod.map{|meth, test| 
          total_tests += test['tests']
          total_passed += test['tests_passed']
        }
      }
    }
  elsif target == "all" or target.nil?
    puts "app testing not impletemented yet: all"
  else
    puts "app testing not impletemented yet: #{target} #{opts[:format]}"
  end
  re["total_tests"] = total_tests
  re["total_passed"] = total_passed
  duration = ((Time.new - start_time) * 100000).to_i/100.0
  re["performance"] = "#{((total_passed.to_f / total_tests.to_f) * 100).to_i}% in #{duration} ms"
  puts re.send("to_#{opts[:format]}")
end