Class: BuildTool::Cfg::EnvironmentDeclarationNodeVisitor

Inherits:
ListVisitor show all
Defined in:
lib/build-tool/cfg/visitor.rb

Instance Attribute Summary

Attributes inherited from MJ::VisitorBase

#configuration

Instance Method Summary collapse

Methods inherited from ListVisitor

#visit, #visit_nodes

Methods inherited from MJ::VisitorBase

#initialize, #visit_Object

Constructor Details

This class inherits a constructor from MJ::VisitorBase

Instance Method Details

#visit_EnvironmentDeclarationNode(node) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/build-tool/cfg/visitor.rb', line 234

def visit_EnvironmentDeclarationNode( node )
    name = node.values[0]
    @environment = configuration.environment( name )
    if @environment.nil?
        @environment = BuildTool::Environment.new( name )
        # Only add a environment to a feature if this is the first time it is declared.
        configuration.add_environment( @environment )
        if !configuration.active_feature.nil?
            @environment.feature = configuration.active_feature
            configuration.active_feature.environments << @environment
        end
    end
    if node.values[1] == :INHERITANCE
        parentName = node.values[2]
        @environment.parent = configuration.environment(parentName)
        if @environment.parent.nil?
            raise ConfigurationError, "Environment #{name} inherits from unknown environment #{parentName}!"
        end
        self.visit_nodes( node.values[3] )
    else
        self.visit_nodes( node.values[1] )
    end
    return @environment
end

#visit_EnvironmentVariableNode(node) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/build-tool/cfg/visitor.rb', line 259

def visit_EnvironmentVariableNode( node )
    case node.values.length
    when 3
        case node.values[1]
        when 'append';  @environment.append( node.values[0], node.values[2] )
        when 'prepend'; @environment.prepend( node.values[0], node.values[2] )
        when 'set';     @environment.set( node.values[0], node.values[2] )
        else raise StandardError, "Unexpected token #{node.values[1]}!"
        end
    when 2
        @environment.set( node.values[0], node.values[1] )
    else
        raise StandardError, "Unexpected number of tokens #{node.values.length} #{node.values.join(', ')}"
    end
end