Class: Ego::Plugin
- Inherits:
-
Object
- Object
- Ego::Plugin
- Defined in:
- lib/ego/plugin.rb
Overview
A plug-in extends Ego with new handlers and other functionality, through a domain-specific language (DSL).
Constant Summary collapse
- @@plugins =
Manifest of all registered plug-ins
{}
- @@context =
Current plug-in context
nil
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#builtin ⇒ Object
readonly
Returns the value of attribute builtin.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.context ⇒ Plugin
Get the currently executing plug-in.
-
.decorate(obj) ⇒ Object
Yield each plug-in body passing
objas a parameter and callingobj#context=. -
.load(paths) ⇒ void
Load all given plug-in paths.
-
.register(name, body, builtin: false) ⇒ Plugin
Register a new plug-in.
Instance Method Summary collapse
-
#initialize(name, body, builtin: false) ⇒ Plugin
constructor
A new instance of Plugin.
Constructor Details
#initialize(name, body, builtin: false) ⇒ Plugin
Returns a new instance of Plugin.
19 20 21 22 23 |
# File 'lib/ego/plugin.rb', line 19 def initialize(name, body, builtin: false) @name = name @body = body @builtin = builtin end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
14 15 16 |
# File 'lib/ego/plugin.rb', line 14 def body @body end |
#builtin ⇒ Object (readonly)
Returns the value of attribute builtin.
14 15 16 |
# File 'lib/ego/plugin.rb', line 14 def builtin @builtin end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/ego/plugin.rb', line 14 def name @name end |
Class Method Details
.context ⇒ Plugin
Get the currently executing plug-in.
64 65 66 |
# File 'lib/ego/plugin.rb', line 64 def self.context @@context end |
.decorate(obj) ⇒ Object
Yield each plug-in body passing obj as a parameter and calling
obj#context=.
51 52 53 54 55 56 57 58 59 |
# File 'lib/ego/plugin.rb', line 51 def self.decorate(obj) @@plugins.each_value do |plugin| @@context = plugin plugin.body.call(obj) @@context = nil end obj end |
.load(paths) ⇒ void
This method returns an undefined value.
Load all given plug-in paths
29 30 31 |
# File 'lib/ego/plugin.rb', line 29 def self.load(paths) paths.each { |path| Kernel.load path } end |
.register(name, body, builtin: false) ⇒ Plugin
You should use Ego.plugin in plug-in scripts, which sets a
plug-in name for you automatically.
Register a new plug-in
42 43 44 |
# File 'lib/ego/plugin.rb', line 42 def self.register(name, body, builtin: false) @@plugins[name] = Plugin.new(name, body, builtin: builtin) end |