Skip to content

Commit

Permalink
Merge pull request #494 from hieptranquoc/bug/#493-should-validate-pl…
Browse files Browse the repository at this point in the history
…ugin-params-before-proceeding

@ #493 | should validate plugin params before proceeding
  • Loading branch information
hoatle authored Oct 9, 2018
2 parents 065f6ad + fc1d021 commit 673384e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 23 deletions.
43 changes: 27 additions & 16 deletions lib/teracy-dev/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,35 @@ def self.sync(plugins)

plugins.each do |plugin|

if !installed_plugins.has_key?(plugin['name']) and plugin['state'] == 'installed'
logger.info("installing plugin: #{plugin}")

if plugin['sources'].nil? or plugin['sources'].empty?
plugin['sources'] = [
"https://rubygems.org/",
"https://gems.hashicorp.com/"
]
end

plugin_manager.install_plugin(plugin['name'], Util.symbolize(plugin))
reload_required = true
unless Util.exist? plugin['name']
logger.warn('Plugin name must be configured')
next
end

if installed_plugins.has_key?(plugin['name']) and plugin['state'] == 'uninstalled'
logger.info("uninstalling plugin: #{plugin['name']}")
plugin_manager.uninstall_plugin(plugin['name'])
reload_required = true
case plugin['state']
when 'installed'
if installed_plugins.empty?
unless Util.exist? plugin['sources']
plugin['sources'] = [
"https://rubygems.org/",
"https://gems.hashicorp.com/"
]
end
end

if !installed_plugins.has_key?(plugin['name'])
logger.info("installing plugin: #{plugin}")
plugin_manager.install_plugin(plugin['name'], Util.symbolize(plugin))
reload_required = true
end
when 'uninstalled'
if installed_plugins.has_key?(plugin['name'])
logger.info("uninstalling plugin: #{plugin['name']}")
plugin_manager.uninstall_plugin(plugin['name'])
reload_required = true
end
else
logger.debug('The plugin state is not set, no action will be taken')
end
end

Expand Down
14 changes: 7 additions & 7 deletions lib/teracy-dev/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ def self.symbolize(obj)
return obj.reduce({}) do |memo, (k, v)|
memo.tap { |m| m[k.to_sym] = symbolize(v) }
end if obj.is_a? Hash
return obj.reduce([]) do |memo, v|

return obj.reduce([]) do |memo, v|
memo << symbolize(v); memo
end if obj.is_a? Array

obj
end

Expand Down Expand Up @@ -134,10 +134,10 @@ def self.override(originHash, sourceHash)
replaced_key = key.to_s.sub(/_u?[ra]_/, '')

if !originHash.has_key?(replaced_key)
if value.class.name == 'Hash'
originHash[key] = {}
elsif value.class.name == 'Array'
originHash[replaced_key] = []
if value.class.name == 'Hash'
originHash[key] = {}
elsif value.class.name == 'Array'
originHash[replaced_key] = []
end
end

Expand Down

0 comments on commit 673384e

Please sign in to comment.