Class: Origen::Application::Plugins

Inherits:
Array show all
Defined in:
lib/origen/application/plugins.rb

Overview

Provides an API for working with the application’s plugins

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

Instance Method Summary collapse

Methods inherited from Array

#dups, #dups?, #dups_with_index, #ids

Constructor Details

#initializePlugins

Returns a new instance of Plugins.



7
8
9
10
11
12
13
14
# File 'lib/origen/application/plugins.rb', line 7

def initialize
  @plugins ||= begin
    top = Origen.app
    Origen._applications_lookup[:name].each do |_name, app|
      self << app unless app == top
    end
  end
end

Instance Method Details

#currentObject

Returns the current plugin’s application instance



37
38
39
40
41
# File 'lib/origen/application/plugins.rb', line 37

def current
  return nil if @disabled
  name = @temporary || @current ||= Origen.app.session.origen_core[:default_plugin]
  find { |p| p.name.to_sym == name } if name
end

#current=(name) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/origen/application/plugins.rb', line 43

def current=(name)
  name = name.to_sym if name
  Origen.app.session.origen_core[:default_plugin] = name
  if name == :none
    @current = nil
  else
    @current = name
  end
end

#defaultObject

Deprecated.


95
96
97
98
# File 'lib/origen/application/plugins.rb', line 95

def default
  Origen.deprecated 'Origen.current_plugin.default is deprecated, use Origen.app.plugins.current instead'
  current
end

#default=(name) ⇒ Object

Deprecated.


77
78
79
80
# File 'lib/origen/application/plugins.rb', line 77

def default=(name)
  Origen.deprecated 'Origen.current_plugin.default= is deprecated, use Origen.app.plugins.current= instead'
  self.current = name
end

#disable_currentObject

Temporarily set the current plugin to nil



63
64
65
66
67
68
69
# File 'lib/origen/application/plugins.rb', line 63

def disable_current
  @disabled = true
  if block_given?
    yield
    @disabled = false
  end
end

#enable_currentObject

Restore the current plugin after an earlier disable



72
73
74
# File 'lib/origen/application/plugins.rb', line 72

def enable_current
  @disabled = false
end

#instanceObject

Deprecated.


89
90
91
92
# File 'lib/origen/application/plugins.rb', line 89

def instance
  Origen.deprecated 'Origen.current_plugin.instance is deprecated, use Origen.app.plugins.current instead'
  current
end

#nameObject

Deprecated.


83
84
85
86
# File 'lib/origen/application/plugins.rb', line 83

def name
  Origen.deprecated 'Origen.current_plugin.name is deprecated, use Origen.app.plugins.current.name instead'
  current.name if current
end

#namesObject

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



32
33
34
# File 'lib/origen/application/plugins.rb', line 32

def names
  map(&:name)
end

#plugin_name_from_path(path) ⇒ Object Also known as: path_within_a_plugin

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



110
111
112
113
114
115
116
117
118
# File 'lib/origen/application/plugins.rb', line 110

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

#shared_commandsObject



100
101
102
103
104
105
106
107
# File 'lib/origen/application/plugins.rb', line 100

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) ⇒ Object



53
54
55
56
57
58
59
60
# File 'lib/origen/application/plugins.rb', line 53

def temporary=(name)
  name = name.to_sym if name
  if name == :none
    @temporary = nil
  else
    @temporary = name
  end
end

#validate_production_status(force = false) ⇒ Object

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



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/origen/application/plugins.rb', line 18

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
      end
    end
  end
end