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
Public: the Scheme the json is related to
Public Class Methods
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
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
Output a nice message for completing
# File lib/cuesmash/jsonconf.rb, line 54 def completed Logger.info 'json updated 👌' end
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
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
Output a nice message for starting
# File lib/cuesmash/jsonconf.rb, line 47 def started Logger.info 'Updating json' end
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