Module: RailsConsole

Defined in:
lib/rails_console.rb

Overview

require ‘rails_console/version’

Constant Summary collapse

BASE_COMMAND =
'ssh -t USER@SERVER \'cd PATH/current && bundle exec rails c production\''
@@deploy_file =
'./config/deploy.rb'

Class Method Summary collapse

Class Method Details

.connectionObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rails_console.rb', line 20

def self.connection
  connection_data = { user: nil, server: nil, path: nil }

  File.open(@@deploy_file, 'r') do |f|
    f.each_line do |line|
      if line =~ /deploy_to/
        connection_data[:path] = line.match(/"([^"]*)"/)[1]
      end

      if line =~ /user/
        connection_data[:user] = line.match(/"([^"]*)"/)[1]
      end

      if line =~ /role/ && line =~ /web/
        connection_data[:server] = line.match(/"([^"]*)"/)[1]
      end

    end
  end

  if connection_data.values.include?(nil)
    puts "ERROR to get data from deploy file."
  else
    command = BASE_COMMAND.gsub('USER', connection_data[:user]).gsub('PATH', connection_data[:path]).gsub('SERVER', connection_data[:server])
    puts "Connecting to #{connection_data[:server]} into #{connection_data[:path]}..."

    system(command)
  end

end

.deploy_fileObject



8
9
10
# File 'lib/rails_console.rb', line 8

def self.deploy_file
  @@deploy_file
end

.deploy_file=(option) ⇒ Object



12
13
14
# File 'lib/rails_console.rb', line 12

def self.deploy_file= option
  @@deploy_file = option
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (RailsConsole)

    the object that the method was called on



16
17
18
# File 'lib/rails_console.rb', line 16

def self.setup(&block)
  yield self
end