Method: Liquidscript::ICR::Context#get
- Defined in:
- lib/liquidscript/icr/context.rb
#get(name, options = {}) ⇒ Variable, Boolean
Retrieves a reference to a variable. If the local context doesn’t have a reference, then it will try a few things; first, it will check to see if that variable is one of our allowed variables; second, it will check if the parent has a reference; otherwise, it will add an undefined reference if this context is associated with a class.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/liquidscript/icr/context.rb', line 108 def get(name, = {}) variables.fetch(name) do case true # If the asking variable is an allowed variable, we'll # allow it, and just return a variable instance. when allowed_variables.include?(name) Variable.new(self, name, :allowed => true) # If we have a parent, we can ask the parent for the # variable. This takes precedence over the class # so we can get a proper reference to the correct # variable. when !!parent parent_get(name, ) # If this context is associated with a class, and # we're not doing a dry run, then we'll add an # undefined. when @class && ![:dry_run] add_undefined(name) # If we are doing a dry run, however, then just let # the caller know that it would have been successful. when @class && [:dry_run] true # If none of those options fit, raise an error. else raise InvalidReferenceError.new(name) end end end |