Skip to content

Commit

Permalink
u3d/cache: refactor code - extract human_name for operating system sy…
Browse files Browse the repository at this point in the history
…mbol
  • Loading branch information
lacostej committed Jan 8, 2018
1 parent 90618b3 commit 9c20be3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/u3d/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@

require 'json'
require 'time'
require 'u3d_core/core_ext/operating_system_symbol'
require 'u3d/unity_versions'
require 'u3d/utils'

module U3d
# Cache stores the informations regarding versions
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
Expand Down Expand Up @@ -134,10 +137,7 @@ def fetch_central_cache(os)
end

def update_cache(os)
platform = 'Windows' if os == :win
platform = 'Mac OSX' if os == :mac
platform = 'Linux' if os == :linux
UI.important "Cache is out of date. Updating cache for #{platform}"
UI.important "Cache is out of date. Updating cache for #{os.human_name}"

@cache ||= {}
@cache[os.id2name] = {}
Expand Down
33 changes: 33 additions & 0 deletions lib/u3d_core/core_ext/operating_system_symbol.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## --- BEGIN LICENSE BLOCK ---
# Copyright (c) 2017-present WeWantToKnow AS
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
## --- END LICENSE BLOCK ---
module CoreExtensions
module OperatingSystem
refine Symbol do
def human_name
return 'Windows' if self == :win
return 'Mac OSX' if self == :mac
return 'Linux' if self == :linux
raise "Not a known operating system symbol #{self}"
end
end
end
end

0 comments on commit 9c20be3

Please sign in to comment.