Skip to content

Commit

Permalink
Move duplicated data_path out of U3d::Cache/U3d::INIparser to U3dCore…
Browse files Browse the repository at this point in the history
…::Helper (#266)
  • Loading branch information
niezbop authored Mar 26, 2018
1 parent 6db85a2 commit 6164402
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
15 changes: 2 additions & 13 deletions lib/u3d/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ module U3d
class Cache
using ::CoreExtensions::OperatingSystem

# Path to the directory containing the cache for the different OS
DEFAULT_LINUX_PATH = File.join(ENV['HOME'], '.u3d').freeze
DEFAULT_MAC_PATH = File.join(ENV['HOME'], 'Library', 'Application Support', 'u3d').freeze
DEFAULT_WINDOWS_PATH = File.join(ENV['HOME'], 'AppData', 'Local', 'u3d').freeze
# Name of the file itself
# Name of the cache file
DEFAULT_NAME = 'cache.json'.freeze
# Maximum duration after which the cache is considered outdated
# Currently set to 24h
Expand Down Expand Up @@ -73,14 +69,7 @@ def initialize(path: nil, force_os: nil, force_refresh: false, offline: false, c
end

def self.default_os_path
case U3dCore::Helper.operating_system
when :linux
DEFAULT_LINUX_PATH
when :mac
DEFAULT_MAC_PATH
when :win
DEFAULT_WINDOWS_PATH
end
U3dCore::Helper.data_path
end

private #-------------------------------------------------------------------
Expand Down
12 changes: 1 addition & 11 deletions lib/u3d/iniparser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ module INIparser
# @!group INI parameters to load and save ini files
#####################################################
INI_NAME = 'unity-%<version>s-%<os>s.ini'.freeze
INI_LINUX_PATH = File.join(ENV['HOME'], '.u3d', 'ini_files').freeze
INI_MAC_PATH = File.join(ENV['HOME'], 'Library', 'Application Support', 'u3d', 'ini_files').freeze
INI_WIN_PATH = File.join(ENV['HOME'], 'AppData', 'Local', 'u3d', 'ini_files').freeze

class << self
def load_ini(version, cached_versions, os: U3dCore::Helper.operating_system, offline: false)
Expand Down Expand Up @@ -106,14 +103,7 @@ def filter_broken_linux(ini_hash)
end

def default_ini_path
case U3dCore::Helper.operating_system
when :linux
INI_LINUX_PATH
when :mac
INI_MAC_PATH
when :win
INI_WIN_PATH
end
File.join(U3dCore::Helper.data_path, 'ini_files')
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions lib/u3d_core/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@

module U3dCore
module Helper
DEFAULT_LINUX_PATH = File.join(ENV['HOME'], '.u3d').freeze
DEFAULT_MAC_PATH = File.join(ENV['HOME'], 'Library', 'Application Support', 'u3d').freeze
DEFAULT_WINDOWS_PATH = File.join(ENV['HOME'], 'AppData', 'Local', 'u3d').freeze

def self.data_path
case operating_system
when :linux
DEFAULT_LINUX_PATH
when :mac
DEFAULT_MAC_PATH
when :win
DEFAULT_WINDOWS_PATH
end
end

# Runs a given command using backticks (`)
# and prints them out using the UI.command method
def self.backticks(command, print: true)
Expand Down

0 comments on commit 6164402

Please sign in to comment.