Skip to content

Commit

Permalink
@ teracyhq#277 | add TeracyDev.extension_lookup_path and TeracyDev::E…
Browse files Browse the repository at this point in the history
…xtension::Manager.manifest APIs
  • Loading branch information
hoatle committed Aug 14, 2018
1 parent c09d781 commit 10c4d1e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
14 changes: 14 additions & 0 deletions lib/teracy-dev.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require_relative 'teracy-dev/logging'
require_relative 'teracy-dev/loader'
require_relative 'teracy-dev/extension/manager'


# define public APIs here
Expand All @@ -24,6 +25,19 @@ def self.register_configurator(configurator)
@@loader.configManager.register(configurator)
end

# find the extension lookup_path by its name
def self.extension_lookup_path(extension_name)
extensions = @@loader.settings['teracy-dev']['extensions'] ||= []
extensions.each do |ext|
manifest = Extension::Manager.manifest(ext)
if manifest['name'] == extension_name
return ext['path']['lookup']
end
end
# extension_name not found
return nil
end

@@loader.start

end
46 changes: 23 additions & 23 deletions lib/teracy-dev/extension/manager.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
module TeracyDev
module Extension
class Manager

def self.manifest(extension)
lookup_path = File.join(TeracyDev::BASE_DIR, extension['path']['lookup'] || 'extensions')
path = File.join(lookup_path, extension['path']['extension'])
manifest_path = File.join(path, 'manifest.yaml')
return YAML.load(File.new(manifest_path))
end

def initialize
@logger = Logging.logger_for(self.class.name)
end
Expand Down Expand Up @@ -50,31 +58,23 @@ def sync(extension)

def validate(extension)
return if extension['enabled'] != true
lookup_path = File.join(TeracyDev::BASE_DIR, extension['path']['lookup'] || 'extensions')
path = File.join(lookup_path, extension['path']['extension'])
manifest_path = File.join(path, 'manifest.yaml')
manifest = Manager.manifest(extension)

if File.exist? manifest_path
manifest = Util.load_yaml_file(manifest_path)
if !Util.exist?(manifest['name']) or !Util.exist?(manifest['version'])
@logger.error("The extension manifest's name and version must be defined: #{manifest}, #{extension}")
abort
end
# check the version requirement
if !Util.require_version_valid?(manifest['version'], extension['require_version'])
@logger.error("`#{extension['require_version']}` is required, but current `#{manifest['version']}`: #{extension}")
@logger.error("The current extension version must be updated to satisfy the requirements above")
abort
end
if !Util.exist?(manifest['name']) or !Util.exist?(manifest['version'])
@logger.error("The extension manifest's name and version must be defined: #{manifest}, #{extension}")
abort
end
# check the version requirement
if !Util.require_version_valid?(manifest['version'], extension['require_version'])
@logger.error("`#{extension['require_version']}` is required, but current `#{manifest['version']}`: #{extension}")
@logger.error("The current extension version must be updated to satisfy the requirements above")
abort
end

# check if teracy-dev version satisfies the manifest['target'] if specified
if Util.exist?(manifest['target']) and !Util.require_version_valid?(TeracyDev::VERSION, manifest['target'])
@logger.error("teracy-dev's current version: #{TeracyDev::VERSION}")
@logger.error("this extension requires teracy-dev version: #{manifest['target']} (#{extension})")
abort
end
else
@logger.error("#{manifest_path} must exist for this extension: #{extension}")
# check if teracy-dev version satisfies the manifest['target'] if specified
if Util.exist?(manifest['target']) and !Util.require_version_valid?(TeracyDev::VERSION, manifest['target'])
@logger.error("teracy-dev's current version: #{TeracyDev::VERSION}")
@logger.error("this extension requires teracy-dev version: #{manifest['target']} (#{extension})")
abort
end
end
Expand Down
5 changes: 2 additions & 3 deletions lib/teracy-dev/loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
require_relative 'config/manager'
require_relative 'settings/manager'


module TeracyDev
class Loader
@@instance = nil

attr_reader :processorsManager, :configManager
attr_reader :processorsManager, :configManager, :settings

def initialize
if !!@@instance
Expand All @@ -27,7 +26,7 @@ def start
@processorsManager = Processors::Manager.new
@configManager = Config::Manager.new
init_system
settings = build_settings().freeze
@settings = build_settings().freeze
require_teracy_dev_version(settings['teracy-dev']['require_version'])
configure_vagrant(settings)
end
Expand Down

0 comments on commit 10c4d1e

Please sign in to comment.