lib/legion/extensions.rb in legionio-0.3.1 vs lib/legion/extensions.rb in legionio-0.3.2

- old
+ new

@@ -134,91 +134,52 @@ Legion::Logging.fatal 'did not match any actor classes' end end def gem_load(gem_name, name) - gem_path = "#{Gem::Specification.find_by_name(gem_name).gem_dir}/lib/legion/extensions/#{name}" - require gem_path + require "#{Gem::Specification.find_by_name(gem_name).gem_dir}/lib/legion/extensions/#{name}" true rescue LoadError => e Legion::Logging.error e.message Legion::Logging.error e.backtrace Legion::Logging.error "gem_path: #{gem_path}" unless gem_path.nil? false end def find_extensions @extensions ||= {} - # puts Gem.install('lex-esphome') - # puts Gem::Installer.new('lex-esphome') - # test = Gem::Installer.new('lex-esphome') - # puts test.install - # puts Gem::Dependency.new('lex-esphome') - # $LOAD_PATH << "#{ENV['GEM_HOME']}/gems/lex-esphome-0.1.0/lib" - # require 'legion/extensions/esphome' - # $LOAD_PATH << "#{ENV['GEM_HOME']}/gems/lex-esphome-0.1.0/lib" - # ENV['MY_RUBY_HOME'] #/Users/miverso2/.rvm/rubies/ruby-2.7.0 - # ENV['GEM_HOME'] # /Users/miverso2/.rvm/gems/ruby-2.7.0 - # require 'rubygems/dependency_installer.rb' - # puts Gem::DependencyInstaller.new.install('lex-esphome') - # puts Gem::Installer.new('lex-esphome').install - # puts Gem::Installer.new('lex-esphome').ensure_loadable_spec - # puts Gem.search('lex-esphome') - # Gem.clear_paths - # require 'legion/extensions/esphome' - - # puts Gem.use_gemdeps - # pp Gem.gemdeps - # puts 'gems things' - # puts Gem.loaded_specs.key? 'lex-esphome' - # pp Gem.loaded_specs.keys - # - # require 'rubygems' - # require 'rubygems/command.rb' - # require 'rubygems/dependency_installer.rb' - # - # Gem::Command.build_args = ARGV - # inst = Gem::DependencyInstaller.new - # puts inst.installed_gems - # puts inst.install 'lex-esphome', install_as_default: true - # puts inst.installed_gems - # puts '....' - # test = Gem::DependencyList.new - # test.add(inst) - # pp test.find_name('lex-esphome') - # pp test.find_name('lex-logger') - # pp test.specs - # pp Gem::DependencyList.from_specs - # pp Gem::DependencyList.from_specs.key? 'lex-logg' - # pp inst - # - # pp Gem.new.all_specs - # load 'legion/extensions/esphome.rb' - # puts Gem.register_default_spec() - # :use_gemdeps, - # :detect_gemdeps, - # :source_date_epoch, - # :gemdeps, - # :register_default_spec, - # :find_unresolved_default_spec, - # :clear_default_specs, - # :loaded_specs, - # :default_path, - Gem::Specification.all_names.each do |gem| next unless gem[0..3] == 'lex-' lex = gem.split('-') @extensions[lex[1]] = { full_gem_name: gem, gem_name: "lex-#{lex[1]}", extension_name: lex[1], version: lex[2], - extension_class: "Legion::Extensions::#{lex[1].capitalize}" } + extension_class: "Legion::Extensions::#{lex[1].split('_').collect(&:capitalize).join}" } end - # Legion::Settings[:extensions].each do |extension| - # puts extension unless @extensions.key? extension - # end + Legion::Settings[:extensions].each do |extension, values| + next if @extensions.key? extension.to_s + next if values[:enabled] == false + next if values[:auto_install] == false + + Legion::Logging.warn "#{extension} is missing, attempting to install automatically.." + install = Gem.install("lex-#{extension}") + Legion::Logging.debug(install) + lex = Gem::Specification.find_by_name("lex-#{extension}") + + @extensions[extension.to_s] = { + full_gem_name: "lex-#{extension}-#{lex.version}", + gem_name: "lex-#{extension}", + extension_name: extension.to_s, + version: lex.version, + extension_class: "Legion::Extensions::#{extension.to_s.split('_').collect(&:capitalize).join}" + } + + rescue StandardError, Gem::MissingSpecError => e + Legion::Logging.error "Failed to auto install #{extension}, e: #{e.message}" + end end end end end