Class: Brandish::Processors::All::Embed

Inherits:
Brandish::Processor::Base show all
Includes:
Brandish::Processor::Block
Defined in:
lib/brandish/processors/all/embed.rb

Overview

Note:

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 value true, 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

#context

Instance Method Summary collapse

Methods included from Brandish::Processor::Block

included, #process_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, options = {})
  super if true.equal?(options[: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.

Returns:

  • ({::Symbol => ::Object})


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.

Returns:

  • (::String, nil)


39
40
41
# File 'lib/brandish/processors/all/embed.rb', line 39

def perform
  Execute.new(execute_context).exec(@body.flatten)
end