Class: Brandish::Processors::All::If
- Inherits:
-
Brandish::Processor::Base
- Object
- Brandish::Processor::Base
- Brandish::Processors::All::If
- Includes:
- Brandish::Processor::Block
- Defined in:
- lib/brandish/processors/all/if.rb
Overview
Using the :embed
option is very dangerous - ONLY USE IF YOU
TRUST THE SOURCE. :embed
provides no sandboxing by default. This
is why its value must be set to be true
exactly, and not
any other value.
Provides both an if
and an unless
block into the output. The
processor takes one option: :embed
. If embed is true
(using
strict equalivalence equal?
), then the if statement takes a single
pair, named "condition"
. This condition is executed using
Execute, and if it is true, and if it is an if
block,
the contents are included; otherwise, if it is false, and if it is
an unless
block, the contents are included; otherwise, they are
ignored. If embed is false
, the block can take multiple pairs, and
each pair is matched to a name. If the pair's value equals the matched
name's value, then the condition is true. If the condition is true,
and the block is an if
block, the contents are included; otherwise,
if it is false, and if it is an unless
block, the contents are
included; otherwise, they are not. The pair conditions that are
matched by default are "format"
and "form"
. If pairs are included
that are not provided, it errors.
Options:
:embed
- Optional. Whether or not the condition should be treaded like an embedded condition. This must be set to the exact value oftrue
for it to be accepted.
Pairs:
"condition"
- Optional. The embedded condition for theif
orunless
block. Only applies if the:embed
option is set."format"
- Optional. If this is provided, and the:embed
option is not set, it is added as a condition."form"
- Optional. If this is provided, and the:embed
option is not set, it is added as a condition.
Instance Attribute Summary
Attributes inherited from Brandish::Processor::Base
Instance Method Summary collapse
-
#meets_conditions? ⇒ ::Boolean
If the name of this block is
"if"
, and all of the conditions are matched as outlined in the class direction, then this returnstrue
; otherwise, if the name of this block is"if"
, and any of the conditions are not matched as outlined in the class description, then this returnsfalse
; otherwise, if the name of this block is anything else (i.e."unless"
), and all of the conditions are matched as outlined in the class description, then this returnsfalse
; otherwise, if any of the conditions are not matched as outlined in the class description, then this returnstrue
. -
#perform ⇒ Parser::Node?
If #meets_conditions? is true, this accepts the body of the block for processing; otherwise, it returns
nil
, effectively causing the body to be ignored.
Methods included from Brandish::Processor::Block
Methods inherited from Brandish::Processor::Base
#accept, #call, #initialize, #postprocess, #process_block, #process_command, #process_root, #process_text, register, #setup
Constructor Details
This class inherits a constructor from Brandish::Processor::Base
Instance Method Details
#meets_conditions? ⇒ ::Boolean
If the name of this block is "if"
, and all of the conditions are
matched as outlined in the class direction, then this returns
true
; otherwise, if the name of this block is "if"
, and any of
the conditions are not matched as outlined in the class description,
then this returns false
; otherwise, if the name of this block is
anything else (i.e. "unless"
), and all of the conditions are
matched as outlined in the class description, then this returns
false
; otherwise, if any of the conditions are not matched as
outlined in the class description, then this returns true
.
77 78 79 |
# File 'lib/brandish/processors/all/if.rb', line 77 def meets_conditions? @name == "if" ? match_conditions : !match_conditions end |
#perform ⇒ Parser::Node?
If #meets_conditions? is true, this accepts the body of the block
for processing; otherwise, it returns nil
, effectively causing
the body to be ignored.
62 63 64 |
# File 'lib/brandish/processors/all/if.rb', line 62 def perform accept(@body) if meets_conditions? end |