Class: Origen::Application::PluginsManager
- Defined in:
- lib/origen/application/plugins_manager.rb
Instance Attribute Summary collapse
-
#temporary ⇒ Object
Returns the temporary plugin instance if set, otherwise nil.
Instance Method Summary collapse
-
#add(plugin_name, version, options) ⇒ Object
Adds the given plugin to the current app.
-
#current ⇒ Object
(also: #instance, #current_plugin_instance)
Returns the current plugin instance, this will be the temporary plugin if set, if not then the current default plugin if set, otherwise nil.
-
#default ⇒ Object
Returns the current plugin instance currently set as the default plugin, otherwise nil.
-
#default=(plugin_name) ⇒ Object
Same as temporary= except it will be remembered in the next Origen thread.
-
#describe(plugin_name) ⇒ Object
Describes the plugin.
- #disable ⇒ Object
- #enable ⇒ Object
-
#list ⇒ Object
Lists all the plugins available on server.
-
#list_added_plugins ⇒ Object
Lists out the currently added plugins within the app on console.
-
#name ⇒ Object
Returns the current plugin name, equivalent to calling current.name.
- #remove(plugin_name) ⇒ Object
-
#update(plugin_name, version) ⇒ Object
Updates the plugin to the supplied version.
-
#valid_plugin_name?(plugin_name) ⇒ Boolean
Checks the given plugin name with the list of installed plugins and returns true if found else returns false.
Instance Attribute Details
#temporary ⇒ Object
Returns the temporary plugin instance if set, otherwise nil
5 6 7 |
# File 'lib/origen/application/plugins_manager.rb', line 5 def temporary @temporary end |
Instance Method Details
#add(plugin_name, version, options) ⇒ Object
Adds the given plugin to the current app
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/origen/application/plugins_manager.rb', line 113 def add(plugin_name, version, ) if plugin_name.class != Symbol plugin_name = plugin_name.to_sym end if !valid_plugin_name?(plugin_name) plugin_data = read_plugin_info_from_server(plugin_name) update_config_file!(vault: plugin_data[:vault], version: version, plugin_name: plugin_name, action: :add, dev_import: [:dev_import]) puts 'Plugin added successfully!' else puts "Plugin #{plugin_name} is already included in this app!" end end |
#current ⇒ Object Also known as: instance, current_plugin_instance
Returns the current plugin instance, this will be the temporary plugin if set, if not then the current default plugin if set, otherwise nil
9 10 11 12 13 14 15 |
# File 'lib/origen/application/plugins_manager.rb', line 9 def current if @disabled || @set_to_nil nil else temporary || default end end |
#default ⇒ Object
Returns the current plugin instance currently set as the default plugin, otherwise nil
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/origen/application/plugins_manager.rb', line 60 def default return @default if @default if name = Origen.app.session.origen_core[:default_plugin] begin @default = find_plugin!(name) rescue # Hit here if what has been set to the default plugin has since been # removed from the application self.default = :none nil end end end |
#default=(plugin_name) ⇒ Object
Same as temporary= except it will be remembered in the next Origen thread. Setting this will also clear any temporary assignment that is currently in effect.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/origen/application/plugins_manager.rb', line 47 def default=(plugin_name) self.temporary = nil if !plugin_name || plugin_name.to_sym == :none @default = nil else @default = find_plugin!(plugin_name) Origen.app.session.origen_core[:default_plugin] = @default.name @default end end |
#describe(plugin_name) ⇒ Object
Describes the plugin
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/origen/application/plugins_manager.rb', line 161 def describe(plugin_name) if plugin_name if plugin_name.class != Symbol plugin_name = plugin_name.to_sym end description = nil Origen.client.plugins.each do |plugin| if plugin[:origen_name].to_sym == plugin_name description = <<-EOT Origen_Name: #{plugin[:origen_name]} Actual Name: #{plugin[:name]} Category: #{plugin[:category]} Description: #{plugin[:description]} EOT break end end if description.nil? puts "Plugin #{plugin_name} not found or it does not include a description" exit 1 end description else puts 'No plugin name provided' exit 1 end end |
#disable ⇒ Object
19 20 21 |
# File 'lib/origen/application/plugins_manager.rb', line 19 def disable @disabled = true end |
#enable ⇒ Object
23 24 25 |
# File 'lib/origen/application/plugins_manager.rb', line 23 def enable @disabled = false end |
#list ⇒ Object
Lists all the plugins available on server
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/origen/application/plugins_manager.rb', line 81 def list puts 'The following plugins are available to add to your application:' puts '' Origen.client.plugins.group_by { |p| p[:category] }.sort_by { |k, _v| k }.each do |category, plugins| puts category.upcase puts '=' * category.length plugins.sort_by { |p| p[:name] }.each do |plugin| line = "#{plugin[:origen_name]}".ljust(25) + plugin[:name].strip.ljust(30) if plugin[:latest_version_prod] || plugin[:latest_version_dev] line += [plugin[:latest_version_prod] || plugin[:latest_version_dev]].compact.join(', ') end puts line end puts '' end end |
#list_added_plugins ⇒ Object
Lists out the currently added plugins within the app on console
148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/origen/application/plugins_manager.rb', line 148 def list_added_plugins puts 'The following plugins are included in this app:' format = "%30s\t%30s\t%30s\n" printf(format, 'Origen_Name', 'Name', 'Version') printf(format, '---------', '----', '-------') Origen.plugins.each do |plugin| printf(format, plugin.name, plugin.config.name, plugin.version) end puts '' end |
#name ⇒ Object
Returns the current plugin name, equivalent to calling current.name
28 29 30 |
# File 'lib/origen/application/plugins_manager.rb', line 28 def name current ? current.name : nil end |
#remove(plugin_name) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/origen/application/plugins_manager.rb', line 131 def remove(plugin_name) if plugin_name.class != Symbol plugin_name = plugin_name.to_sym end if valid_plugin_name?(plugin_name) update_config_file!(plugin_name: plugin_name, action: :remove) if File.exist?("#{imports_dir}/#{plugin_name}") FileUtils.rm_rf("#{imports_dir}/#{plugin_name}") puts "Plugin '#{plugin_name}' removed successfully!" end else puts "Plugin #{plugin_name} not found in this app!" end end |
#update(plugin_name, version) ⇒ Object
Updates the plugin to the supplied version
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/origen/application/plugins_manager.rb', line 99 def update(plugin_name, version) if plugin_name.class != Symbol plugin_name = plugin_name.to_sym end if valid_plugin_name?(plugin_name) update_config_file!(version: version, plugin_name: plugin_name, action: :update) else puts "Plugin #{plugin_name} not found in this app!" end end |
#valid_plugin_name?(plugin_name) ⇒ Boolean
Checks the given plugin name with the list of installed plugins and returns true if found else returns false
76 77 78 |
# File 'lib/origen/application/plugins_manager.rb', line 76 def valid_plugin_name?(plugin_name) Origen.import_manager.names.include?(plugin_name) end |