class Origen::Application::Plugins

Provides an API for working with the application’s plugins

An instance of this class is instantiated as Origen.app.plugins

Public Class Methods

new() click to toggle source
# File lib/origen/application/plugins.rb, line 7
def initialize
  top = Origen.app
  Origen._applications_lookup[:name].each do |_name, app|
    self << app unless app == top
  end
end

Public Instance Methods

current() click to toggle source

Returns the current plugin’s application instance

# File lib/origen/application/plugins.rb, line 38
def current
  return nil if @temporary == :none
  return nil if @disabled

  name = @temporary || @current ||= if Origen.app.session.origen_core[:default_plugin]
                                      Origen.app.session.origen_core[:default_plugin]
                                    elsif Origen.app.config.default_plugin && !Origen.app.session.origen_core[:default_plugin_cleared_by_user]
                                      Origen.app.config.default_plugin
                                    end

  find { |p| p.name.to_sym == name } if name
end
current=(name) click to toggle source
# File lib/origen/application/plugins.rb, line 51
def current=(name)
  name = name.to_sym if name
  if name == :none || name.nil?
    @current = nil
    Origen.app.session.origen_core[:default_plugin] = nil
    Origen.app.session.origen_core[:default_plugin_cleared_by_user] = true
  else
    Origen.app.session.origen_core[:default_plugin] = name
    @current = name
  end
end
default() click to toggle source

@deprecated

# File lib/origen/application/plugins.rb, line 101
def default
  Origen.deprecated 'Origen.current_plugin.default is deprecated, use Origen.app.plugins.current instead'
  current
end
default=(name) click to toggle source

@deprecated

# File lib/origen/application/plugins.rb, line 83
def default=(name)
  Origen.deprecated 'Origen.current_plugin.default= is deprecated, use Origen.app.plugins.current= instead'
  self.current = name
end
disable_current() { || ... } click to toggle source

Temporarily set the current plugin to nil

# File lib/origen/application/plugins.rb, line 69
def disable_current
  @disabled = true
  if block_given?
    yield
    @disabled = false
  end
end
enable_current() click to toggle source

Restore the current plugin after an earlier disable

# File lib/origen/application/plugins.rb, line 78
def enable_current
  @disabled = false
end
instance() click to toggle source

@deprecated

# File lib/origen/application/plugins.rb, line 95
def instance
  Origen.deprecated 'Origen.current_plugin.instance is deprecated, use Origen.app.plugins.current instead'
  current
end
name() click to toggle source

@deprecated

# File lib/origen/application/plugins.rb, line 89
def name
  Origen.deprecated 'Origen.current_plugin.name is deprecated, use Origen.app.plugins.current.name instead'
  current.name if current
end
names() click to toggle source

Returns an array of symbols that represent the names of all plugins

# File lib/origen/application/plugins.rb, line 33
def names
  map(&:name)
end
path_within_a_plugin(path)
plugin_name_from_path(path) click to toggle source

Return the plugin name if the path specified is from that plugin

# File lib/origen/application/plugins.rb, line 116
def plugin_name_from_path(path)
  path = Pathname.new(path).expand_path.cleanpath
  each do |plugin|
    if path.to_s =~ /^#{plugin.root}/
      return plugin.name
    end
  end
  nil
end
Also aliased as: path_within_a_plugin
shared_commands() click to toggle source
# File lib/origen/application/plugins.rb, line 106
def shared_commands
  [Origen.app, self].flatten.map do |plugin|
    shared = plugin.config.shared || {}
    if shared[:command_launcher]
      "#{plugin.root}/#{shared[:command_launcher]}"
    end
  end.compact
end
temporary=(name) click to toggle source
# File lib/origen/application/plugins.rb, line 63
def temporary=(name)
  name = name.to_sym if name
  @temporary = name
end
validate_production_status(force = false) click to toggle source

Will raise an error if any plugins are currently imported from a path reference in the Gemfile

# File lib/origen/application/plugins.rb, line 16
def validate_production_status(force = false)
  if Origen.mode.production? || force
    if File.exist?("#{Origen.root}/Gemfile")
      File.readlines("#{Origen.root}/Gemfile").each do |line|
        # http://rubular.com/r/yNGDGB6M2r
        if line =~ /^\s*gem\s+(("|')\w+("|')),.*(:path\s*=>|path:)/
          fail "The following gem is defined as a path in your Gemfile, but that is not allowed in production: #{Regexp.last_match[1]}"
        end
        if line =~ /ORIGEN PLUGIN AUTO-GENERATED/
          fail 'Fetched gems are currently being used in your Gemfile, but that is not allowed in production!'
        end
      end
    end
  end
end