class Cuesmash::JsonConf

Cuesmash needs to create a json file in the iOS or Android project to trick the simulator into connecting to a sinatra server instead

@author [jarod]

Attributes

app_path[RW]
file_name[RW]

Public: the Scheme the json is related to

port[RW]

Public Class Methods

new(app_path:, file_name: 'server_config', port:) click to toggle source

Create a new json instance @param scheme [String] The scheme related to the json @param app_path [String] The dir where the app is going to be placed. @param file_name [String] Default: server_config. The name of the file with the server configurations.

@return [JsonConf] A JsonConf instance

# File lib/cuesmash/jsonconf.rb, line 26
def initialize(app_path:, file_name: 'server_config', port:)
  @file_name = file_name
  @app_path = app_path
  @port = port
end

Public Instance Methods

execute() click to toggle source

Executes the json tasks update and clear the old jsons

# File lib/cuesmash/jsonconf.rb, line 35
def execute
  started
  update

  completed
end

Private Instance Methods

completed() click to toggle source

Output a nice message for completing

# File lib/cuesmash/jsonconf.rb, line 54
def completed
  Logger.info 'json updated 👌'
end
server_ip() click to toggle source

The local IP address of the mock backend server

@return [String] The mock backends IP

# File lib/cuesmash/jsonconf.rb, line 75
def server_ip
  Socket.ip_address_list.find { |a| a.ipv4? && !a.ipv4_loopback? }.ip_address
end
server_json_path() click to toggle source

The path to the server config json

@return [String] The full path to the server config json

# File lib/cuesmash/jsonconf.rb, line 83
def server_json_path
  @app_path + "/#{@file_name}.json"
end
started() click to toggle source

Output a nice message for starting

# File lib/cuesmash/jsonconf.rb, line 47
def started
  Logger.info 'Updating json'
end
update() click to toggle source

Update the Xcode applications server.json file with sinatras port and URL

# File lib/cuesmash/jsonconf.rb, line 62
def update
  data = {
    url_preference: "#{server_ip}",
    port_preference: "#{@port}"
  }

  File.write(server_json_path, data.to_json)
end