Class: Liquidscript::ICR::Set
- Includes:
- Representable
- Defined in:
- lib/liquidscript/icr/set.rb
Overview
Represents a set of instruction codes. Can contain metadata about the set, like whether or not it can be inlined, if a new context needs to be applied, etc.
Instance Attribute Summary
Attributes inherited from Code
#action, #arguments, #metadata
Instance Method Summary collapse
- #<<(*v) ⇒ Object (also: #push)
-
#add(action, *arguments) ⇒ Object
Adds a code to the code list.
-
#codes ⇒ Array<Code>
Outputs the codes in this set.
- #context ⇒ Object
- #context=(context) ⇒ Object
-
#hidden ⇒ Array<Symbol>
A list of hidden variables in the current context.
-
#initialize ⇒ Set
constructor
Initialize the set.
-
#locals ⇒ Array<Symbol>
A list of all the local variables in the current scope.
-
#parameters ⇒ Array<Symbol>
A list of components (or arguments) that are in the current scope.
- #parent ⇒ Object
- #parent=(parent) ⇒ Object
-
#to_a ⇒ Array
Turns the code into an array, containing the action and the arguments.
-
#variables ⇒ Array<Symbol>
A list of all variables in the current scope.
Methods included from Representable
#to_a!, #to_ary, #to_sexp, #to_yaml
Methods inherited from Code
#[], #[]=, #method_missing, #respond_to_missing?, #value?
Constructor Details
#initialize ⇒ Set
Initialize the set.
13 14 15 16 |
# File 'lib/liquidscript/icr/set.rb', line 13 def initialize @context = nil super :exec end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Liquidscript::ICR::Code
Instance Method Details
#<<(*v) ⇒ Object Also known as: push
66 67 68 69 70 |
# File 'lib/liquidscript/icr/set.rb', line 66 def <<(*v) v.select { |p| p }.each do |part| @arguments << part end end |
#add(action, *arguments) ⇒ Object
Adds a code to the code list. This is just a convienince method.
62 63 64 |
# File 'lib/liquidscript/icr/set.rb', line 62 def add(action, *arguments) self << Code.new(action, arguments) end |
#codes ⇒ Array<Code>
Outputs the codes in this set.
114 115 116 |
# File 'lib/liquidscript/icr/set.rb', line 114 def codes @arguments end |
#context ⇒ Object
19 20 21 |
# File 'lib/liquidscript/icr/set.rb', line 19 def context @context || @metadata.fetch(:parent).context end |
#context=(context) ⇒ Object
37 38 39 |
# File 'lib/liquidscript/icr/set.rb', line 37 def context=(context) @context = context end |
#hidden ⇒ Array<Symbol>
A list of hidden variables in the current context.
99 100 101 |
# File 'lib/liquidscript/icr/set.rb', line 99 def hidden context.hidden.map(&:name) end |
#locals ⇒ Array<Symbol>
A list of all the local variables in the current scope. Local variables are defined as variables that were a) not passed in by function execution as arguments and b) are set within the current context.
81 82 83 |
# File 'lib/liquidscript/icr/set.rb', line 81 def locals variables - parameters - hidden end |
#parameters ⇒ Array<Symbol>
A list of components (or arguments) that are in the current scope. Defined as variables that were passed in by function execution as arguments.
91 92 93 |
# File 'lib/liquidscript/icr/set.rb', line 91 def parameters context.parameters.map(&:name) end |
#parent ⇒ Object
32 33 34 |
# File 'lib/liquidscript/icr/set.rb', line 32 def parent @metadata[:parent] end |
#parent=(parent) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/liquidscript/icr/set.rb', line 23 def parent=(parent) @metadata[:parent] = parent if @context @context.parent = parent.context end parent end |
#to_a ⇒ Array
Turns the code into an array, containing the action and the arguments. Note that changing this array will not change the code.
46 47 48 49 50 51 52 53 54 |
# File 'lib/liquidscript/icr/set.rb', line 46 def to_a part = [@action] part << [:_context, context] if @context part.concat(@metadata.to_a.select { |(k, v)| [:arguments, :heredocs, :herenum].include?(k) }.map { |(k, v)| [:"_#{k}", v] }) part.concat(@arguments) part end |
#variables ⇒ Array<Symbol>
A list of all variables in the current scope.
107 108 109 |
# File 'lib/liquidscript/icr/set.rb', line 107 def variables context.variables.keys - context.allowed_variables end |