Class: Brandish::Processors::All::Embed
- Inherits:
-
Brandish::Processor::Base
- Object
- Brandish::Processor::Base
- Brandish::Processors::All::Embed
- Includes:
- Brandish::Processor::Block
- Defined in:
- lib/brandish/processors/all/embed.rb
Overview
This is very dangerous - ONLY USE IF YOU TRUST THE SOURCE. This processor provides no sandboxing by default.
Provides a block that allows Ruby code to be executed within it.
Options:
:really
- Optional. If this isn't the exact valuetrue
, this processor is never added to the context, preventing embed blocks from being used.
This takes no specific pairs; however, the embedded execution context has access to all of the pairs that are passed to the element.
Instance Attribute Summary
Attributes inherited from Brandish::Processor::Base
Instance Method Summary collapse
-
#execute_context ⇒ {::Symbol => ::Object}
The context that is passed to Execute#initialize.
-
#initialize(context, options = {}) ⇒ Embed
constructor
A new instance of Embed.
-
#perform ⇒ ::String?
Creates a Execute instance and executes the code.
Methods included from Brandish::Processor::Block
Methods inherited from Brandish::Processor::Base
#accept, #call, #postprocess, #process_block, #process_command, #process_root, #process_text, register, #setup
Constructor Details
#initialize(context, options = {}) ⇒ Embed
Returns a new instance of Embed.
28 29 30 |
# File 'lib/brandish/processors/all/embed.rb', line 28 def initialize(context, = {}) super if true.equal?([:really]) end |
Instance Method Details
#execute_context ⇒ {::Symbol => ::Object}
The context that is passed to Execute#initialize. This provides the context, the "pairs" that were passed to the block, the options that were passed to the processor, the format that it is being executed in, and the form name.
49 50 51 52 |
# File 'lib/brandish/processors/all/embed.rb', line 49 def execute_context { context: @context, pairs: @pairs, options: @options, format: @context.form.format, form: @context.form.name } end |
#perform ⇒ ::String?
Creates a Execute instance and executes the code. This returns the return value of the code executed; therefore, if the code returns a string value, it is added to the output; otherwise, if it returns a nil value, it is ignored. Those are the only two values that should be returned; others will be rejected.
39 40 41 |
# File 'lib/brandish/processors/all/embed.rb', line 39 def perform Execute.new(execute_context).exec(@body.flatten) end |