How to use load method of Plugins Package

Best Inspec_ruby code snippet using Plugins.load

loader.rb

Source:loader.rb Github

copy

Full Screen

...4 class Loader5 attr_reader :initializer6 # Creates a new Plugin::Loader instance, associated with the given7 # Rails::Initializer. This default implementation automatically locates8 # all plugins, and adds all plugin load paths, when it is created. The plugins9 # are then fully loaded (init.rb is evaluated) when load_plugins is called.10 #11 # It is the loader's responsibility to ensure that only the plugins specified12 # in the configuration are actually loaded, and that the order defined13 # is respected.14 def initialize(initializer)15 @initializer = initializer16 end17 18 # Returns the plugins to be loaded, in the order they should be loaded.19 def plugins20 @plugins ||= all_plugins.select { |plugin| should_load?(plugin) }.sort { |p1, p2| order_plugins(p1, p2) }21 end22 # Returns all the plugins that could be found by the current locators.23 def all_plugins24 @all_plugins ||= locate_plugins25 @all_plugins26 end27 28 def load_plugins29 plugins.each do |plugin| 30 plugin.load(initializer)31 register_plugin_as_loaded(plugin)32 end33 ensure_all_registered_plugins_are_loaded!34 end35 36 # Adds the load paths for every plugin into the $LOAD_PATH. Plugin load paths are37 # added *after* the application's <tt>lib</tt> directory, to ensure that an application38 # can always override code within a plugin.39 #40 # Plugin load paths are also added to Dependencies.load_paths, and Dependencies.load_once_paths. 41 def add_plugin_load_paths42 plugins.each do |plugin|43 plugin.load_paths.each do |path|44 $LOAD_PATH.insert(application_lib_index + 1, path)45 ActiveSupport::Dependencies.load_paths << path46 unless Rails.configuration.reload_plugins?47 ActiveSupport::Dependencies.load_once_paths << path48 end49 end50 end51 $LOAD_PATH.uniq!52 end 53 54 protected55 56 # The locate_plugins method uses each class in config.plugin_locators to57 # find the set of all plugins available to this Rails application.58 def locate_plugins59 configuration.plugin_locators.map { |locator|60 locator.new(initializer).plugins61 }.flatten62 # TODO: sorting based on config.plugins63 end64 def register_plugin_as_loaded(plugin)65 initializer.loaded_plugins << plugin66 end67 def configuration68 initializer.configuration69 end70 71 def should_load?(plugin)72 # uses Plugin#name and Plugin#valid?73 enabled?(plugin) && plugin.valid?74 end75 def order_plugins(plugin_a, plugin_b)76 if !explicit_plugin_loading_order?77 plugin_a <=> plugin_b78 else79 if !explicitly_enabled?(plugin_a) && !explicitly_enabled?(plugin_b)80 plugin_a <=> plugin_b81 else82 effective_order_of(plugin_a) <=> effective_order_of(plugin_b)83 end 84 end85 end86 87 def effective_order_of(plugin)88 if explicitly_enabled?(plugin)89 registered_plugin_names.index(plugin.name) 90 else91 registered_plugin_names.index('all')92 end 93 end94 def application_lib_index95 $LOAD_PATH.index(File.join(RAILS_ROOT, 'lib')) || 096 end 97 def enabled?(plugin)98 !explicit_plugin_loading_order? || registered?(plugin)99 end100 def explicit_plugin_loading_order?101 !registered_plugin_names.nil?102 end103 def registered?(plugin)104 explicit_plugin_loading_order? && registered_plugins_names_plugin?(plugin)105 end106 def explicitly_enabled?(plugin)107 !explicit_plugin_loading_order? || explicitly_registered?(plugin)108 end109 def explicitly_registered?(plugin)110 explicit_plugin_loading_order? && registered_plugin_names.include?(plugin.name)111 end112 113 def registered_plugins_names_plugin?(plugin)114 registered_plugin_names.include?(plugin.name) || registered_plugin_names.include?('all')115 end116 117 # The plugins that have been explicitly listed with config.plugins. If this list is nil118 # then it means the client does not care which plugins or in what order they are loaded, 119 # so we load all in alphabetical order. If it is an empty array, we load no plugins, if it is120 # non empty, we load the named plugins in the order specified.121 def registered_plugin_names122 configuration.plugins ? configuration.plugins.map(&:to_s) : nil123 end124 125 def loaded?(plugin_name)126 initializer.loaded_plugins.detect { |plugin| plugin.name == plugin_name.to_s }127 end128 129 def ensure_all_registered_plugins_are_loaded!130 if explicit_plugin_loading_order?131 if configuration.plugins.detect {|plugin| plugin != :all && !loaded?(plugin) }132 missing_plugins = configuration.plugins - (plugins + [:all])133 raise LoadError, "Could not locate the following plugins: #{missing_plugins.to_sentence}"134 end135 end136 end137 138 end139 end140end...

Full Screen

Full Screen

load

Using AI Code Generation

copy

Full Screen

1Plugins.load('1.rb')2Plugins.load('2.rb')3Plugins.load('3.rb')4Plugins.load('4.rb')5Plugins.load('5.rb')6Plugins.load('6.rb')7Plugins.load('7.rb')8Plugins.load('8.rb')9Plugins.load('9.rb')10Plugins.load('10.rb')11Plugins.load('11.rb')12Plugins.load('12.rb')13Plugins.load('13.rb')14Plugins.load('14.rb')15Plugins.load('15.rb')16Plugins.load('16.rb')17Plugins.load('17.rb')18Plugins.load('18.rb')19Plugins.load('19.rb')

Full Screen

Full Screen

load

Using AI Code Generation

copy

Full Screen

1Plugins.load('plugin1.rb')2Plugins.load('plugin2.rb')3 def self.load(filename)4 def self.load(filename)5The first example requires the code to load a plugin to be Plugins.load('plugin1.rb') . The second example requires the code to load a plugin to be require '

Full Screen

Full Screen

load

Using AI Code Generation

copy

Full Screen

1Plugins.load("plugin1.rb")2Plugins.load("plugin2.rb")3Plugins.load("plugin3.rb")4Plugins.load("plugin4.rb")5Plugins.load("plugin5.rb")6Plugins.load("plugin6.rb")7Plugins.load("plugin7.rb")8Plugins.load("plugin8.rb")9Plugins.load("plugin9.rb")10Plugins.load("plugin10.rb")11Plugins.load("plugin11.rb")12Plugins.load("plugin12.rb")13Plugins.load("plugin13.rb")

Full Screen

Full Screen

load

Using AI Code Generation

copy

Full Screen

1Plugins.new.load("plugin.rb")2Plugins.new.load("plugin.rb")3Plugins.new.load("plugin.rb")4Plugins.new.load("plugin.rb")5Plugins.new.load("plugin.rb")6Plugins.new.load("plugin.rb")7Plugins.new.load("plugin.rb")8Plugins.new.load("plugin.rb")9Plugins.new.load("plugin.rb")

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Inspec_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful