Module: HyperMesh::AutoCreate

Included in:
Connection, Connection::QueuedMessage
Defined in:
lib/synchromesh/connection.rb

Instance Method Summary collapse

Instance Method Details

#create_table(*args, &block) ⇒ Object



18
19
20
# File 'lib/synchromesh/connection.rb', line 18

def create_table(*args, &block)
  connection.create_table(table_name, *args, &block) if needs_init?
end

#needs_init?Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/synchromesh/connection.rb', line 3

def needs_init?
  return true unless connection.tables.include?(table_name)
  return false unless HyperMesh.on_server?
  return true if defined?(Rails::Server)
  return true unless Connection.root_path
  uri = URI("#{Connection.root_path}server_up")
  http = Net::HTTP.new(uri.host, uri.port)
  request = Net::HTTP::Get.new(uri.path)
  if uri.scheme == 'https'
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  http.request(request) && return rescue true
end