lib/liquidscript/icr/set.rb in liquidscript-0.9.2 vs lib/liquidscript/icr/set.rb in liquidscript-0.10.0
- old
+ new
@@ -16,23 +16,26 @@
# Initialize the set.
def initialize
@metadata = {}
@code = []
+ @contexts = []
@action = :exec
end
#
def context
- @metadata.fetch(:context) do
- @metadata.fetch(:parent).context
- end
+ contexts.last || @metadata.fetch(:parent).context
end
+ def contexts
+ @contexts
+ end
+
#
def context=(new_context)
- @metadata[:context] = new_context
+ contexts << new_context
end
# Adds a code to the code list. This is just a
# convienince method.
#
@@ -87,14 +90,14 @@
# {#method_missing} - that actually operates on
# the internal array.
#
# @return [Array]
def to_a
- [
- @action,
- *@metadata.to_a.map { |(m, i)| [:"_#{m}", i] },
- *@code
- ]
+ part = [@action]
+ part << [:_context, context] if contexts.any?
+ part.concat(@metadata.to_a.map { |(m, i)| [:"_#{m}", i] })
+ part.concat(@code)
+ part
end
# Outputs the codes in this set.
#
# @return [Array<Code>]