Class: Faceter::Rules::PrependNested Private

Inherits:
AbstractMapper::PairRule
  • Object
show all
Defined in:
lib/faceter/rules/prepend_nested.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Optimizes AST by moving nested nodes from the array level to one level deeper:

Examples:

Removes unnecessary iterations by items of the same array.

prefix "foo", nested: true
list do
  # ...
end

# Becomes:
list do
  prefix "foo", nested: true
  # ...
end

Removes “flat” operation that cannot be applied to non-hashes

prefix "foo", nested: false
list do
  # ...
end

# Becomes:
list do
  # ...
end

Instance Method Summary collapse

Instance Method Details

#optimizeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
# File 'lib/faceter/rules/prepend_nested.rb', line 43

def optimize
  Nodes::List.new { (left.nested ? [left] : []) + right.entries }
end

#optimize?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


38
39
40
# File 'lib/faceter/rules/prepend_nested.rb', line 38

def optimize?
  left.respond_to?(:nested) && right.instance_of?(Nodes::List)
end