Class: Puppet::Pops::Model::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/pops/model/factory.rb

Overview

TODO:

All those uppercase methods … they look bad in one way, but stand out nicely in the grammar… decide if they should change into lower case names (some of the are lower case)…

Factory is a helper class that makes construction of a Pops Model much more convenient. It can be viewed as a small internal DSL for model constructions. For usage see tests using the factory.

API:

  • public

Constant Summary collapse

Model =

API:

  • public

Puppet::Pops::Model
STATEMENT_CALLS =

API:

  • public

{
  'require' => true,
  'realize' => true,
  'include' => true,
  'contain' => true,
  'tag'     => true,

  'debug'   => true,
  'info'    => true,
  'notice'  => true,
  'warning' => true,
  'error'   => true,

  'fail'    => true,
  'import'  => true  # discontinued, but transform it to make it call error reporting function
}
@@build_visitor =

Shared build_visitor, since there are many instances of Factory being used

API:

  • public

Puppet::Pops::Visitor.new(self, "build")
@@interpolation_visitor =

API:

  • public

Puppet::Pops::Visitor.new(self, "interpolate")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(o, *args) ⇒ Factory

Initialize a factory with a single object, or a class with arguments applied to build of created instance

API:

  • public



23
24
25
26
27
28
29
30
31
32
# File 'lib/puppet/pops/model/factory.rb', line 23

def initialize o, *args
  @current = case o
  when Model::PopsObject
    o
  when Puppet::Pops::Model::Factory
    o.current
  else
    build(o, *args)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object

Catch all delegation to current

API:

  • public



468
469
470
471
472
473
474
# File 'lib/puppet/pops/model/factory.rb', line 468

def method_missing(meth, *args, &block)
  if current.respond_to?(meth)
    current.send(meth, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#currentObject Also known as: model

API:

  • public



12
13
14
# File 'lib/puppet/pops/model/factory.rb', line 12

def current
  @current
end

Class Method Details

.ATTR(name, type_expr = nil) ⇒ Object

API:

  • public



568
# File 'lib/puppet/pops/model/factory.rb', line 568

def self.ATTR(name, type_expr=nil);    new(Model::CreateAttributeExpression, name, type_expr); end

.ATTRIBUTE_OP(name, op, expr) ⇒ Object

API:

  • public



693
694
695
# File 'lib/puppet/pops/model/factory.rb', line 693

def self.ATTRIBUTE_OP(name, op, expr)
  new(Model::AttributeOperation, name, op, expr)
end

.ATTRIBUTES_OP(expr) ⇒ Object

API:

  • public



697
698
699
# File 'lib/puppet/pops/model/factory.rb', line 697

def self.ATTRIBUTES_OP(expr)
  new(Model::AttributesOperation, expr)
end

.block(*args) ⇒ Object

API:

  • public



550
# File 'lib/puppet/pops/model/factory.rb', line 550

def self.block(*args);                 new(Model::BlockExpression, *args);                     end

.block_or_expression(*args) ⇒ Object

Builds a BlockExpression if args size > 1, else the single expression/value in args

API:

  • public



741
742
743
744
745
746
747
# File 'lib/puppet/pops/model/factory.rb', line 741

def self.block_or_expression(*args)
  if args.size > 1
    new(Model::BlockExpression, *args)
  else
    new(args[0])
  end
end

.CALL_METHOD(functor, argument_list) ⇒ Object

API:

  • public



708
709
710
# File 'lib/puppet/pops/model/factory.rb', line 708

def self.CALL_METHOD(functor, argument_list)
  new(Model::CallMethodExpression, functor, true, nil, *argument_list)
end

.CALL_NAMED(name, rval_required, argument_list) ⇒ Object

API:

  • public



701
702
703
704
705
706
# File 'lib/puppet/pops/model/factory.rb', line 701

def self.CALL_NAMED(name, rval_required, argument_list)
  unless name.kind_of?(Model::PopsObject)
    name = Puppet::Pops::Model::Factory.fqn(name) unless name.is_a?(Puppet::Pops::Model::Factory)
  end
  new(Model::CallNamedFunctionExpression, name, rval_required, *argument_list)
end

.CASE(test_e, *options) ⇒ Object

API:

  • public



560
# File 'lib/puppet/pops/model/factory.rb', line 560

def self.CASE(test_e,*options);        new(Model::CaseExpression, test_e, *options);           end

.COLLECT(type_expr, query_expr, attribute_operations) ⇒ Object

API:

  • public



712
713
714
# File 'lib/puppet/pops/model/factory.rb', line 712

def self.COLLECT(type_expr, query_expr, attribute_operations)
  new(Model::CollectExpression, type_expr, query_expr, attribute_operations)
end

.concat(*args) ⇒ Object

API:

  • public



1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
# File 'lib/puppet/pops/model/factory.rb', line 1023

def self.concat(*args)
  new(args.map do |e|
    e = e.current if e.is_a?(self)
    case e
    when Model::LiteralString
      e.value
    when String
      e
    else
      raise ArgumentError, "can only concatenate strings, got #{e.class}"
    end
  end.join(''))
end

.DEFINITION(name, parameters, body) ⇒ Object

API:

  • public



753
754
755
# File 'lib/puppet/pops/model/factory.rb', line 753

def self.DEFINITION(name, parameters, body)
  new(Model::ResourceTypeDefinition, name, parameters, body)
end

.ENUM(*args) ⇒ Object

API:

  • public



570
# File 'lib/puppet/pops/model/factory.rb', line 570

def self.ENUM(*args);                  new(Model::CreateEnumExpression, *args);                end

.EPP(parameters, body) ⇒ Object

API:

  • public



630
631
632
633
634
635
636
637
638
639
# File 'lib/puppet/pops/model/factory.rb', line 630

def self.EPP(parameters, body)
  if parameters.nil?
    params = []
    parameters_specified = false
  else
    params = parameters
    parameters_specified = true
  end
  LAMBDA(params, new(Model::EppExpression, parameters_specified, body))
end

.EXPORTED_QUERY(query_expr) ⇒ Object

API:

  • public



689
690
691
# File 'lib/puppet/pops/model/factory.rb', line 689

def self.EXPORTED_QUERY(query_expr)
  new(Model::ExportedQuery, query_expr)
end

.fqn(o) ⇒ Object

Creates a QualifiedName representation of o, unless o already represents a QualifiedName in which case it is returned.

API:

  • public



602
603
604
605
606
# File 'lib/puppet/pops/model/factory.rb', line 602

def self.fqn(o)
  o = o.current if o.is_a?(Puppet::Pops::Model::Factory)
  o = new(Model::QualifiedName, o) unless o.is_a? Model::QualifiedName
  o
end

.fqr(o) ⇒ Object

Creates a QualifiedName representation of o, unless o already represents a QualifiedName in which case it is returned.

API:

  • public



611
612
613
614
615
# File 'lib/puppet/pops/model/factory.rb', line 611

def self.fqr(o)
  o = o.current if o.is_a?(Puppet::Pops::Model::Factory)
  o = new(Model::QualifiedReference, o) unless o.is_a? Model::QualifiedReference
  o
end

.HASH(entries) ⇒ Object

API:

  • public



574
# File 'lib/puppet/pops/model/factory.rb', line 574

def self.HASH(entries);                new(Model::LiteralHash, *entries);                      end

.HEREDOC(name, expr) ⇒ Object

API:

  • public



576
# File 'lib/puppet/pops/model/factory.rb', line 576

def self.HEREDOC(name, expr);          new(Model::HeredocExpression, name, expr);              end

.HOSTCLASS(name, parameters, parent, body) ⇒ Object

API:

  • public



749
750
751
# File 'lib/puppet/pops/model/factory.rb', line 749

def self.HOSTCLASS(name, parameters, parent, body)
  new(Model::HostClassDefinition, name, parameters, parent, body)
end

.IF(test_e, then_e, else_e) ⇒ Object

API:

  • public



556
# File 'lib/puppet/pops/model/factory.rb', line 556

def self.IF(test_e,then_e,else_e);     new(Model::IfExpression, test_e, then_e, else_e);       end

.KEY_ENTRY(key, val) ⇒ Object

API:

  • public



572
# File 'lib/puppet/pops/model/factory.rb', line 572

def self.KEY_ENTRY(key, val);          new(Model::KeyedEntry, key, val);                       end

.LAMBDA(parameters, body) ⇒ Object

API:

  • public



757
758
759
# File 'lib/puppet/pops/model/factory.rb', line 757

def self.LAMBDA(parameters, body)
  new(Model::LambdaExpression, parameters, body)
end

.LIST(entries) ⇒ Object

API:

  • public



580
# File 'lib/puppet/pops/model/factory.rb', line 580

def self.LIST(entries);                new(Model::LiteralList, *entries);                      end

.literal(o) ⇒ Object

Factory starting points

API:

  • public



542
# File 'lib/puppet/pops/model/factory.rb', line 542

def self.literal(o);                   new(o);                                                 end

.MAP(match, value) ⇒ Object

API:

  • public



564
# File 'lib/puppet/pops/model/factory.rb', line 564

def self.MAP(match, value);            new(Model::SelectorEntry, match, value);                end

.minus(o) ⇒ Object

API:

  • public



544
# File 'lib/puppet/pops/model/factory.rb', line 544

def self.minus(o);                     new(o).minus;                                           end

.NAMED_ACCESS(type_name, bodies) ⇒ Object

API:

  • public



716
717
718
# File 'lib/puppet/pops/model/factory.rb', line 716

def self.NAMED_ACCESS(type_name, bodies)
  new(Model::NamedAccessExpression, type_name, bodies)
end

.NODE(hosts, parent, body) ⇒ Object

API:

  • public



584
# File 'lib/puppet/pops/model/factory.rb', line 584

def self.NODE(hosts, parent, body);    new(Model::NodeDefinition, hosts, parent, body);        end

.nop?(o) ⇒ Boolean

Returns:

API:

  • public



761
762
763
# File 'lib/puppet/pops/model/factory.rb', line 761

def self.nop? o
  o.nil? || o.is_a?(Puppet::Pops::Model::Nop)
end

.NUMBER(name_or_numeric) ⇒ Object

API:

  • public



652
653
654
655
656
657
658
659
660
661
662
663
664
# File 'lib/puppet/pops/model/factory.rb', line 652

def self.NUMBER(name_or_numeric)
  if n_radix = Puppet::Pops::Utils.to_n_with_radix(name_or_numeric)
    val, radix = n_radix
    if val.is_a?(Float)
      new(Model::LiteralFloat, val)
    else
      new(Model::LiteralInteger, val, radix)
    end
  else
    # Bad number should already have been caught by lexer - this should never happen
    raise ArgumentError, "Internal Error, NUMBER token does not contain a valid number, #{name_or_numeric}"
  end
end

.PARAM(name, expr = nil) ⇒ Object

API:

  • public



582
# File 'lib/puppet/pops/model/factory.rb', line 582

def self.PARAM(name, expr=nil);        new(Model::Parameter, name, expr);                      end

.PROGRAM(body, definitions, locator) ⇒ Object

API:

  • public



736
737
738
# File 'lib/puppet/pops/model/factory.rb', line 736

def self.PROGRAM(body, definitions, locator)
  new(Model::Program, body, definitions, locator)
end

.QNAME(name) ⇒ Object

TODO: This is the same a fqn factory method, don’t know if callers to fqn and QNAME can live with the same result or not yet - refactor into one method when decided.

API:

  • public



648
649
650
# File 'lib/puppet/pops/model/factory.rb', line 648

def self.QNAME(name)
  new(Model::QualifiedName, name)
end

.QNAME_OR_NUMBER(name) ⇒ Object

Convert input string to either a qualified name, a LiteralInteger with radix, or a LiteralFloat

API:

  • public



668
669
670
671
672
673
674
675
676
677
678
679
# File 'lib/puppet/pops/model/factory.rb', line 668

def self.QNAME_OR_NUMBER(name)
  if n_radix = Puppet::Pops::Utils.to_n_with_radix(name)
    val, radix = n_radix
    if val.is_a?(Float)
      new(Model::LiteralFloat, val)
    else
      new(Model::LiteralInteger, val, radix)
    end
  else
    new(Model::QualifiedName, name)
  end
end

.QREF(name) ⇒ Object

API:

  • public



681
682
683
# File 'lib/puppet/pops/model/factory.rb', line 681

def self.QREF(name)
  new(Model::QualifiedReference, name)
end

.record_position(o, start_locatable, end_locateable) ⇒ Object

API:

  • public



480
481
482
# File 'lib/puppet/pops/model/factory.rb', line 480

def self.record_position(o, start_locatable, end_locateable)
  new(o).record_position(start_locatable, end_locateable)
end

.RENDER_EXPR(expr) ⇒ Object

API:

  • public



626
627
628
# File 'lib/puppet/pops/model/factory.rb', line 626

def self.RENDER_EXPR(expr)
  new(Model::RenderExpression, expr)
end

.RENDER_STRING(o) ⇒ Object

TODO_EPP

API:

  • public



622
623
624
# File 'lib/puppet/pops/model/factory.rb', line 622

def self.RENDER_STRING(o)
  new(Model::RenderStringExpression, o)
end

.RESERVED(name) ⇒ Object

API:

  • public



641
642
643
# File 'lib/puppet/pops/model/factory.rb', line 641

def self.RESERVED(name)
  new(Model::ReservedWord, name)
end

.RESOURCE(type_name, bodies) ⇒ Object

API:

  • public



720
721
722
# File 'lib/puppet/pops/model/factory.rb', line 720

def self.RESOURCE(type_name, bodies)
  new(Model::ResourceExpression, type_name, bodies)
end

.RESOURCE_BODY(resource_title, attribute_operations) ⇒ Object

API:

  • public



732
733
734
# File 'lib/puppet/pops/model/factory.rb', line 732

def self.RESOURCE_BODY(resource_title, attribute_operations)
  new(Model::ResourceBody, resource_title, attribute_operations)
end

.RESOURCE_DEFAULTS(type_name, attribute_operations) ⇒ Object

API:

  • public



724
725
726
# File 'lib/puppet/pops/model/factory.rb', line 724

def self.RESOURCE_DEFAULTS(type_name, attribute_operations)
  new(Model::ResourceDefaultsExpression, type_name, attribute_operations)
end

.RESOURCE_OVERRIDE(resource_ref, attribute_operations) ⇒ Object

API:

  • public



728
729
730
# File 'lib/puppet/pops/model/factory.rb', line 728

def self.RESOURCE_OVERRIDE(resource_ref, attribute_operations)
  new(Model::ResourceOverrideExpression, resource_ref, attribute_operations)
end

.resource_shape(expr) ⇒ Object

Returns symbolic information about an expected shape of a resource expression given the LHS of a resource expr.

  • ‘name { }` => :resource, create a resource of the given type

  • ‘Name { }` => ’:defaults`, set defaults for the referenced type

  • ‘Name[] { }` => :override, overrides instances referenced by LHS

  • _any other_ => ‘:error’, all other are considered illegal

API:

  • public



520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
# File 'lib/puppet/pops/model/factory.rb', line 520

def self.resource_shape(expr)
  expr = expr.current if expr.is_a?(Puppet::Pops::Model::Factory)
  case expr
  when Model::QualifiedName
    :resource
  when Model::QualifiedReference
    :defaults
  when Model::AccessExpression
    # if Resource[e], then it is not resource specific
    if expr.left_expr.is_a?(Model::QualifiedReference) && expr.left_expr.value == 'resource' && expr.keys.size == 1
      :defaults
    else
      :override
    end
  when 'class'
    :class
  else
    :error
  end
end

.set_resource_form(expr, form) ⇒ Object

Sets the form of the resource expression (:regular (the default), :virtual, or :exported). Produces true if the expression was a resource expression, false otherwise.

API:

  • public



505
506
507
508
509
510
511
# File 'lib/puppet/pops/model/factory.rb', line 505

def self.set_resource_form(expr, form)
  expr = expr.current if expr.is_a?(Puppet::Pops::Model::Factory)
  # Note: Validation handles illegal combinations
  return false unless expr.is_a?(Puppet::Pops::Model::AbstractResource)
  expr.form = form
  return true
end

.string(*args) ⇒ Object

API:

  • public



552
# File 'lib/puppet/pops/model/factory.rb', line 552

def self.string(*args);                new(Model::ConcatenatedString, *args);                  end

.SUBLOCATE(token, expr) ⇒ Object

API:

  • public



578
# File 'lib/puppet/pops/model/factory.rb', line 578

def self.SUBLOCATE(token, expr)        new(Model::SubLocatedExpression, token, expr);          end

.TEXT(expr) ⇒ Object

API:

  • public



617
618
619
# File 'lib/puppet/pops/model/factory.rb', line 617

def self.TEXT(expr)
  new(Model::TextExpression, new(expr).interpolate)
end

.text(o) ⇒ Object

API:

  • public



554
# File 'lib/puppet/pops/model/factory.rb', line 554

def self.text(o);                      new(o).text;                                            end

.transform_calls(expressions) ⇒ Object

Transforms an array of expressions containing literal name expressions to calls if followed by an expression, or expression list.

API:

  • public



791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
# File 'lib/puppet/pops/model/factory.rb', line 791

def self.transform_calls(expressions)
  expressions.reduce([]) do |memo, expr|
    expr = expr.current if expr.is_a?(Puppet::Pops::Model::Factory)
    name = memo[-1]
    if name.is_a?(Model::QualifiedName) && STATEMENT_CALLS[name.value]
      the_call = Puppet::Pops::Model::Factory.CALL_NAMED(name, false, expr.is_a?(Array) ? expr : [expr])
      # last positioned is last arg if there are several
      record_position(the_call, name, expr.is_a?(Array) ? expr[-1]  : expr)
      memo[-1] = the_call
      if expr.is_a?(Model::CallNamedFunctionExpression)
        # Patch statement function call to expression style
        # This is needed because it is first parsed as a "statement" and the requirement changes as it becomes
        # an argument to the name to call transform above.
        expr.rval_required = true
      end
    else
      memo << expr
      if expr.is_a?(Model::CallNamedFunctionExpression)
        # Patch rvalue expression function call to statement style.
        # This is not really required but done to be AST model compliant
        expr.rval_required = false
      end
    end
    memo
  end

end

.transform_resource_wo_title(left, attribute_ops) ⇒ Object

Transforms a left expression followed by an untitled resource (in the form of attribute_operations)

Parameters:

  • the lhs followed what may be a hash

API:

  • public



821
822
823
824
825
826
827
828
829
830
831
# File 'lib/puppet/pops/model/factory.rb', line 821

def self.transform_resource_wo_title(left, attribute_ops)
  # Returning nil means accepting the given as a potential resource expression
  return nil unless attribute_ops.is_a? Array
  return nil unless left.current.is_a?(Puppet::Pops::Model::QualifiedName)
  keyed_entries = attribute_ops.map do |ao|
    return nil if ao.operator == :'+>'
    KEY_ENTRY(ao.attribute_name, ao.value_expr)
  end
  result = block_or_expression(*transform_calls([left, HASH(keyed_entries)]))
  result
end

.TYPE(name, super_name = nil) ⇒ Object

API:

  • public



566
# File 'lib/puppet/pops/model/factory.rb', line 566

def self.TYPE(name, super_name=nil);   new(Model::CreateTypeExpression, name, super_name);     end

.unfold(o) ⇒ Object

API:

  • public



546
# File 'lib/puppet/pops/model/factory.rb', line 546

def self.unfold(o);                    new(o).unfold;                                          end

.UNLESS(test_e, then_e, else_e) ⇒ Object

API:

  • public



558
# File 'lib/puppet/pops/model/factory.rb', line 558

def self.UNLESS(test_e,then_e,else_e); new(Model::UnlessExpression, test_e, then_e, else_e);   end

.var(o) ⇒ Object

API:

  • public



548
# File 'lib/puppet/pops/model/factory.rb', line 548

def self.var(o);                       new(o).var;                                             end

.VIRTUAL_QUERY(query_expr) ⇒ Object

API:

  • public



685
686
687
# File 'lib/puppet/pops/model/factory.rb', line 685

def self.VIRTUAL_QUERY(query_expr)
  new(Model::VirtualQuery, query_expr)
end

.WHEN(values_list, block) ⇒ Object

API:

  • public



562
# File 'lib/puppet/pops/model/factory.rb', line 562

def self.WHEN(values_list, block);     new(Model::CaseOption, values_list, block);             end

Instance Method Details

#%(r) ⇒ Object

API:

  • public



404
# File 'lib/puppet/pops/model/factory.rb', line 404

def % r;      f_arithmetic(:%, r);                                      end

#*(r) ⇒ Object

API:

  • public



402
# File 'lib/puppet/pops/model/factory.rb', line 402

def * r;      f_arithmetic(:*, r);                                      end

#+(r) ⇒ Object

API:

  • public



396
# File 'lib/puppet/pops/model/factory.rb', line 396

def + r;      f_arithmetic(:+, r);                                      end

#-(r) ⇒ Object

API:

  • public



398
# File 'lib/puppet/pops/model/factory.rb', line 398

def - r;      f_arithmetic(:-, r);                                      end

#/(r) ⇒ Object

API:

  • public



400
# File 'lib/puppet/pops/model/factory.rb', line 400

def / r;      f_arithmetic(:/, r);                                      end

#<(r) ⇒ Object

API:

  • public



410
# File 'lib/puppet/pops/model/factory.rb', line 410

def < r;      f_comparison(:<, r);                                      end

#<<(r) ⇒ Object

API:

  • public



406
# File 'lib/puppet/pops/model/factory.rb', line 406

def << r;     f_arithmetic(:<<, r);                                     end

#<=(r) ⇒ Object

API:

  • public



412
# File 'lib/puppet/pops/model/factory.rb', line 412

def <= r;     f_comparison(:<=, r);                                     end

#==(r) ⇒ Object

API:

  • public



418
# File 'lib/puppet/pops/model/factory.rb', line 418

def == r;     f_comparison(:==, r);                                     end

#=~(r) ⇒ Object

API:

  • public



422
# File 'lib/puppet/pops/model/factory.rb', line 422

def =~ r;     f_match(:'=~', r);                                        end

#>(r) ⇒ Object

API:

  • public



414
# File 'lib/puppet/pops/model/factory.rb', line 414

def > r;      f_comparison(:>, r);                                      end

#>=(r) ⇒ Object

API:

  • public



416
# File 'lib/puppet/pops/model/factory.rb', line 416

def >= r;     f_comparison(:>=, r);                                     end

#>>(r) ⇒ Object

API:

  • public



408
# File 'lib/puppet/pops/model/factory.rb', line 408

def >> r;     f_arithmetic(:>>, r);                                     end

#[](*r) ⇒ Object

API:

  • public



392
# File 'lib/puppet/pops/model/factory.rb', line 392

def [](*r);   f_build_vararg(Model::AccessExpression, current, *r);     end

#and(r) ⇒ Object

API:

  • public



380
# File 'lib/puppet/pops/model/factory.rb', line 380

def and(r)    f_build_binary(Model::AndExpression, current, r);         end

#attributes(*args) ⇒ Object

API:

  • public



462
463
464
465
# File 'lib/puppet/pops/model/factory.rb', line 462

def attributes(*args)
  args.each {|a| current.addAttributes(build(a)) }
  self
end

#build(o, *args) ⇒ Object

Polymorphic build

API:

  • public



35
36
37
38
39
40
41
42
# File 'lib/puppet/pops/model/factory.rb', line 35

def build(o, *args)
  begin
    @@build_visitor.visit_this(self, o, *args)
  rescue =>e
    # debug here when in trouble...
    raise e
  end
end

#build_AccessExpression(o, left, *keys) ⇒ Object

API:

  • public



78
79
80
81
82
# File 'lib/puppet/pops/model/factory.rb', line 78

def build_AccessExpression(o, left, *keys)
  o.left_expr = to_ops(left)
  keys.each {|expr| o.addKeys(to_ops(expr)) }
  o
end

#build_ArithmeticExpression(o, op, a, b) ⇒ Object

Building of Model classes

API:

  • public



56
57
58
59
# File 'lib/puppet/pops/model/factory.rb', line 56

def build_ArithmeticExpression(o, op, a, b)
  o.operator = op
  build_BinaryExpression(o, a, b)
end

#build_Array(o) ⇒ Object

Creates a LiteralList instruction from an Array, where the entries are built.

API:

  • public



906
907
908
909
910
# File 'lib/puppet/pops/model/factory.rb', line 906

def build_Array(o)
  x = Model::LiteralList.new
  o.each { |v| x.addValues(build(v)) }
  x
end

#build_AssignmentExpression(o, op, a, b) ⇒ Object

API:

  • public



61
62
63
64
# File 'lib/puppet/pops/model/factory.rb', line 61

def build_AssignmentExpression(o, op, a, b)
  o.operator = op
  build_BinaryExpression(o, a, b)
end

#build_AttributeOperation(o, name, op, value) ⇒ Object

API:

  • public



66
67
68
69
70
71
# File 'lib/puppet/pops/model/factory.rb', line 66

def build_AttributeOperation(o, name, op, value)
  o.operator = op
  o.attribute_name = name.to_s # BOOLEAN is allowed in the grammar
  o.value_expr = build(value)
  o
end

#build_AttributesOperation(o, value) ⇒ Object

API:

  • public



73
74
75
76
# File 'lib/puppet/pops/model/factory.rb', line 73

def build_AttributesOperation(o, value)
  o.expr = build(value)
  o
end

#build_BinaryExpression(o, left, right) ⇒ Object

API:

  • public



84
85
86
87
88
# File 'lib/puppet/pops/model/factory.rb', line 84

def build_BinaryExpression(o, left, right)
  o.left_expr = to_ops(left)
  o.right_expr = to_ops(right)
  o
end

#build_BlockExpression(o, *args) ⇒ Object

API:

  • public



90
91
92
93
# File 'lib/puppet/pops/model/factory.rb', line 90

def build_BlockExpression(o, *args)
  args.each {|expr| o.addStatements(to_ops(expr)) }
  o
end

#build_CallExpression(o, functor, rval_required, *args) ⇒ Object

Parameters:

  • if the call must produce a value

API:

  • public



922
923
924
925
926
927
# File 'lib/puppet/pops/model/factory.rb', line 922

def build_CallExpression(o, functor, rval_required, *args)
  o.functor_expr = to_ops(functor)
  o.rval_required = rval_required
  args.each {|x| o.addArguments(to_ops(x)) }
  o
end

#build_CallMethodExpression(o, functor, rval_required, lambda, *args) ⇒ Object

API:

  • public



929
930
931
932
933
# File 'lib/puppet/pops/model/factory.rb', line 929

def build_CallMethodExpression(o, functor, rval_required, lambda, *args)
  build_CallExpression(o, functor, rval_required, *args)
  o.lambda = lambda
  o
end

#build_CaseExpression(o, test, *args) ⇒ Object

API:

  • public



935
936
937
938
939
# File 'lib/puppet/pops/model/factory.rb', line 935

def build_CaseExpression(o, test, *args)
  o.test = build(test)
  args.each {|opt| o.addOptions(build(opt)) }
  o
end

#build_CaseOption(o, value_list, then_expr) ⇒ Object

API:

  • public



941
942
943
944
945
946
947
# File 'lib/puppet/pops/model/factory.rb', line 941

def build_CaseOption(o, value_list, then_expr)
  value_list = [value_list] unless value_list.is_a? Array
  value_list.each { |v| o.addValues(build(v)) }
  b = f_build_body(then_expr)
  o.then_expr = to_ops(b) if b
  o
end

#build_Class(o, *args) ⇒ Object

Build a Class by creating an instance of it, and then calling build on the created instance with the given arguments

API:

  • public



951
952
953
# File 'lib/puppet/pops/model/factory.rb', line 951

def build_Class(o, *args)
  build(o.new(), *args)
end

#build_CollectExpression(o, type_expr, query_expr, attribute_operations) ⇒ Object

API:

  • public



95
96
97
98
99
100
# File 'lib/puppet/pops/model/factory.rb', line 95

def build_CollectExpression(o, type_expr, query_expr, attribute_operations)
  o.type_expr = to_ops(type_expr)
  o.query = build(query_expr)
  attribute_operations.each {|op| o.addOperations(build(op)) }
  o
end

#build_ComparisonExpression(o, op, a, b) ⇒ Object

API:

  • public



102
103
104
105
# File 'lib/puppet/pops/model/factory.rb', line 102

def build_ComparisonExpression(o, op, a, b)
  o.operator = op
  build_BinaryExpression(o, a, b)
end

#build_ConcatenatedString(o, *args) ⇒ Object

API:

  • public



107
108
109
110
# File 'lib/puppet/pops/model/factory.rb', line 107

def build_ConcatenatedString(o, *args)
  args.each {|expr| o.addSegments(build(expr)) }
  o
end

#build_CreateAttributeExpression(o, name, datatype_expr) ⇒ Object

API:

  • public



124
125
126
127
128
# File 'lib/puppet/pops/model/factory.rb', line 124

def build_CreateAttributeExpression(o, name, datatype_expr)
  o.name = name
  o.type = to_ops(datatype_expr)
  o
end

#build_CreateEnumExpression(o, *args) ⇒ Object

API:

  • public



118
119
120
121
122
# File 'lib/puppet/pops/model/factory.rb', line 118

def build_CreateEnumExpression(o, *args)
  o.name = args.slice(0) if args.size == 2
  o.values = build(args.last)
  o
end

#build_CreateTypeExpression(o, name, super_name = nil) ⇒ Object

API:

  • public



112
113
114
115
116
# File 'lib/puppet/pops/model/factory.rb', line 112

def build_CreateTypeExpression(o, name, super_name = nil)
  o.name = name
  o.super_name = super_name
  o
end

#build_EppExpression(o, parameters_specified, body) ⇒ Object

API:

  • public



879
880
881
882
883
884
# File 'lib/puppet/pops/model/factory.rb', line 879

def build_EppExpression(o, parameters_specified, body)
  o.parameters_specified = parameters_specified
  b = f_build_body(body)
  o.body = b.current if b
  o
end

#build_Factory(o) ⇒ Object

If building a factory, simply unwrap the model oject contained in the factory.

API:

  • public



887
888
889
# File 'lib/puppet/pops/model/factory.rb', line 887

def build_Factory(o)
  o.current
end

#build_FalseClass(o) ⇒ Object

API:

  • public



855
856
857
858
859
# File 'lib/puppet/pops/model/factory.rb', line 855

def build_FalseClass(o)
  x = Model::LiteralBoolean.new
  x.value = o
  x
end

#build_Fixnum(o) ⇒ Object

API:

  • public



861
862
863
864
865
# File 'lib/puppet/pops/model/factory.rb', line 861

def build_Fixnum(o)
  x = Model::LiteralInteger.new
  x.value = o;
  x
end

#build_Float(o) ⇒ Object

API:

  • public



867
868
869
870
871
# File 'lib/puppet/pops/model/factory.rb', line 867

def build_Float(o)
  x = Model::LiteralFloat.new
  x.value = o;
  x
end

#build_Hash(o) ⇒ Object

Create a LiteralHash instruction from a hash, where keys and values are built The hash entries are added in sorted order based on key.to_s

API:

  • public



915
916
917
918
919
# File 'lib/puppet/pops/model/factory.rb', line 915

def build_Hash(o)
  x = Model::LiteralHash.new
  (o.sort_by {|k,v| k.to_s}).each {|k,v| x.addEntries(build(Model::KeyedEntry.new, k, v)) }
  x
end

#build_HeredocExpression(o, name, expr) ⇒ Object

API:

  • public



130
131
132
133
134
# File 'lib/puppet/pops/model/factory.rb', line 130

def build_HeredocExpression(o, name, expr)
  o.syntax = name
  o.text_expr = build(expr)
  o
end

#build_HostClassDefinition(o, name, parameters, parent_class_name, body) ⇒ Model::HostClassDefinition

Returns configured from the parameters.

Parameters:

  • a valid classname

  • may be empty

  • a valid classname referencing a parent class, optional.

  • expression that constitute the body

Returns:

  • configured from the parameters

API:

  • public



142
143
144
145
146
# File 'lib/puppet/pops/model/factory.rb', line 142

def build_HostClassDefinition(o, name, parameters, parent_class_name, body)
  build_NamedDefinition(o, name, parameters, body)
  o.parent_class = parent_class_name if parent_class_name
  o
end

#build_IfExpression(o, t, ift, els) ⇒ Object

API:

  • public



186
187
188
189
190
191
# File 'lib/puppet/pops/model/factory.rb', line 186

def build_IfExpression(o, t, ift, els)
  o.test = build(t)
  o.then_expr = build(ift)
  o.else_expr= build(els)
  o
end

#build_KeyedEntry(o, k, v) ⇒ Object

API:

  • public



159
160
161
162
163
# File 'lib/puppet/pops/model/factory.rb', line 159

def build_KeyedEntry(o, k, v)
  o.key = to_ops(k)
  o.value = to_ops(v)
  o
end

#build_LambdaExpression(o, parameters, body) ⇒ Object

API:

  • public



218
219
220
221
222
223
# File 'lib/puppet/pops/model/factory.rb', line 218

def build_LambdaExpression(o, parameters, body)
  parameters.each {|p| o.addParameters(build(p)) }
  b = f_build_body(body)
  o.body = to_ops(b) if b
  o
end

#build_LiteralFloat(o, val) ⇒ Object

API:

  • public



175
176
177
178
# File 'lib/puppet/pops/model/factory.rb', line 175

def build_LiteralFloat(o, val)
  o.value = val
  o
end

#build_LiteralHash(o, *keyed_entries) ⇒ Object

API:

  • public



165
166
167
168
# File 'lib/puppet/pops/model/factory.rb', line 165

def build_LiteralHash(o, *keyed_entries)
  keyed_entries.each {|entry| o.addEntries build(entry) }
  o
end

#build_LiteralInteger(o, val, radix) ⇒ Object

API:

  • public



180
181
182
183
184
# File 'lib/puppet/pops/model/factory.rb', line 180

def build_LiteralInteger(o, val, radix)
  o.value = val
  o.radix = radix
  o
end

#build_LiteralList(o, *values) ⇒ Object

API:

  • public



170
171
172
173
# File 'lib/puppet/pops/model/factory.rb', line 170

def build_LiteralList(o, *values)
  values.each {|v| o.addValues build(v) }
  o
end

#build_MatchExpression(o, op, a, b) ⇒ Object

API:

  • public



193
194
195
196
# File 'lib/puppet/pops/model/factory.rb', line 193

def build_MatchExpression(o, op, a, b)
  o.operator = op
  build_BinaryExpression(o, a, b)
end

#build_NamedDefinition(o, name, parameters, body) ⇒ Object

API:

  • public



225
226
227
228
229
230
231
# File 'lib/puppet/pops/model/factory.rb', line 225

def build_NamedDefinition(o, name, parameters, body)
  parameters.each {|p| o.addParameters(build(p)) }
  b = f_build_body(body)
  o.body = b.current if b
  o.name = name
  o
end

#build_NilClass(o) ⇒ Object

API:

  • public



844
845
846
847
# File 'lib/puppet/pops/model/factory.rb', line 844

def build_NilClass(o)
  x = Model::Nop.new
  x
end

#build_NodeDefinition(o, hosts, parent, body) ⇒ Object

Parameters:

API:

  • public



237
238
239
240
241
242
243
# File 'lib/puppet/pops/model/factory.rb', line 237

def build_NodeDefinition(o, hosts, parent, body)
  hosts.each {|h| o.addHost_matches(build(h)) }
  o.parent = build(parent) if parent # no nop here
  b = f_build_body(body)
  o.body = b.current if b
  o
end

#build_Parameter(o, name, expr) ⇒ Object

API:

  • public



245
246
247
248
249
# File 'lib/puppet/pops/model/factory.rb', line 245

def build_Parameter(o, name, expr)
  o.name = name
  o.value = build(expr) if expr # don't build a nil/nop
  o
end

#build_Program(o, body, definitions, locator) ⇒ Object

API:

  • public



326
327
328
329
330
331
332
333
334
335
# File 'lib/puppet/pops/model/factory.rb', line 326

def build_Program(o, body, definitions, locator)
  o.body = to_ops(body)
  # non containment
  definitions.each { |d| o.addDefinitions(d) }
  o.source_ref = locator.file
  o.source_text = locator.string
  o.line_offsets = locator.line_index
  o.locator = locator
  o
end

#build_QualifiedName(o, name) ⇒ Object

API:

  • public



337
338
339
340
# File 'lib/puppet/pops/model/factory.rb', line 337

def build_QualifiedName(o, name)
  o.value = name.to_s
  o
end

#build_QualifiedReference(o, name) ⇒ Object

API:

  • public



251
252
253
254
# File 'lib/puppet/pops/model/factory.rb', line 251

def build_QualifiedReference(o, name)
  o.value = name.to_s.downcase
  o
end

#build_QueryExpression(o, expr) ⇒ Object

API:

  • public



314
315
316
317
318
# File 'lib/puppet/pops/model/factory.rb', line 314

def build_QueryExpression(o, expr)
  ops = to_ops(expr)
  o.expr = ops unless Puppet::Pops::Model::Factory.nop? ops
  o
end

#build_Regexp(o) ⇒ Object

API:

  • public



873
874
875
876
877
# File 'lib/puppet/pops/model/factory.rb', line 873

def build_Regexp(o)
  x = Model::LiteralRegularExpression.new
  x.value = o;
  x
end

#build_RelationshipExpression(o, op, a, b) ⇒ Object

API:

  • public



256
257
258
259
# File 'lib/puppet/pops/model/factory.rb', line 256

def build_RelationshipExpression(o, op, a, b)
  o.operator = op
  build_BinaryExpression(o, a, b)
end

#build_RenderStringExpression(o, string) ⇒ Object

API:

  • public



267
268
269
270
# File 'lib/puppet/pops/model/factory.rb', line 267

def build_RenderStringExpression(o, string)
  o.value = string;
  o
end

#build_ReservedWord(o, name) ⇒ Object

API:

  • public



154
155
156
157
# File 'lib/puppet/pops/model/factory.rb', line 154

def build_ReservedWord(o, name)
  o.word = name
  o
end

#build_ResourceBody(o, title_expression, attribute_operations) ⇒ Object

API:

  • public



272
273
274
275
276
# File 'lib/puppet/pops/model/factory.rb', line 272

def build_ResourceBody(o, title_expression, attribute_operations)
  o.title = build(title_expression)
  attribute_operations.each {|ao| o.addOperations(build(ao)) }
  o
end

#build_ResourceDefaultsExpression(o, type_ref, attribute_operations) ⇒ Object

API:

  • public



278
279
280
281
282
# File 'lib/puppet/pops/model/factory.rb', line 278

def build_ResourceDefaultsExpression(o, type_ref, attribute_operations)
  o.type_ref = build(type_ref)
  attribute_operations.each {|ao| o.addOperations(build(ao)) }
  o
end

#build_ResourceExpression(o, type_name, bodies) ⇒ Object

API:

  • public



261
262
263
264
265
# File 'lib/puppet/pops/model/factory.rb', line 261

def build_ResourceExpression(o, type_name, bodies)
  o.type_name = build(type_name)
  bodies.each {|b| o.addBodies(build(b)) }
  o
end

#build_ResourceOverrideExpression(o, resources, attribute_operations) ⇒ Object

API:

  • public



148
149
150
151
152
# File 'lib/puppet/pops/model/factory.rb', line 148

def build_ResourceOverrideExpression(o, resources, attribute_operations)
  o.resources = build(resources)
  attribute_operations.each {|ao| o.addOperations(build(ao)) }
  o
end

#build_SelectorEntry(o, matching, value) ⇒ Object

API:

  • public



308
309
310
311
312
# File 'lib/puppet/pops/model/factory.rb', line 308

def build_SelectorEntry(o, matching, value)
  o.matching_expr = build(matching)
  o.value_expr = build(value)
  o
end

#build_SelectorExpression(o, left, *selectors) ⇒ Object

API:

  • public



284
285
286
287
288
# File 'lib/puppet/pops/model/factory.rb', line 284

def build_SelectorExpression(o, left, *selectors)
  o.left_expr = to_ops(left)
  selectors.each {|s| o.addSelectors(build(s)) }
  o
end

#build_String(o) ⇒ Object

Building model equivalences of Ruby objects Allows passing regular ruby objects to the factory to produce instructions that when evaluated produce the same thing.

API:

  • public



838
839
840
841
842
# File 'lib/puppet/pops/model/factory.rb', line 838

def build_String(o)
  x = Model::LiteralString.new
  x.value = o;
  x
end

#build_SubLocatedExpression(o, token, expression) ⇒ Object

Builds a SubLocatedExpression - this wraps the expression in a sublocation configured from the given token A SubLocated holds its own locator that is used for subexpressions holding positions relative to what it describes.

API:

  • public



295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/puppet/pops/model/factory.rb', line 295

def build_SubLocatedExpression(o, token, expression)
  o.expr = build(expression)
  o.offset = token.offset
  o.length =  token.length
  locator = token.locator
  o.locator = locator
  o.leading_line_count = locator.leading_line_count
  o.leading_line_offset = locator.leading_line_offset
  # Index is held in sublocator's parent locator - needed to be able to reconstruct
  o.line_offsets = locator.locator.line_index
  o
end

#build_Symbol(o) ⇒ Object

Creates a String literal, unless the symbol is one of the special :undef, or :default which instead creates a LiterlUndef, or a LiteralDefault. Supports :undef because nil creates a no-op instruction.

API:

  • public



894
895
896
897
898
899
900
901
902
903
# File 'lib/puppet/pops/model/factory.rb', line 894

def build_Symbol(o)
  case o
  when :undef
    Model::LiteralUndef.new
  when :default
    Model::LiteralDefault.new
  else
    build_String(o.to_s)
  end
end

#build_TokenValue(o) ⇒ Object

API:

  • public



342
343
344
# File 'lib/puppet/pops/model/factory.rb', line 342

def build_TokenValue(o)
  raise "Factory can not deal with a Lexer Token. Got token: #{o}. Probably caused by wrong index in grammar val[n]."
end

#build_TrueClass(o) ⇒ Object

API:

  • public



849
850
851
852
853
# File 'lib/puppet/pops/model/factory.rb', line 849

def build_TrueClass(o)
  x = Model::LiteralBoolean.new
  x.value = o
  x
end

#build_UnaryExpression(o, expr) ⇒ Object

API:

  • public



320
321
322
323
324
# File 'lib/puppet/pops/model/factory.rb', line 320

def build_UnaryExpression(o, expr)
  ops = to_ops(expr)
  o.expr = ops unless Puppet::Pops::Model::Factory.nop? ops
  o
end

#captures_restObject

Mark parameter as capturing the rest of arguments

API:

  • public



590
591
592
# File 'lib/puppet/pops/model/factory.rb', line 590

def captures_rest()
  current.captures_rest = true
end

#default(r) ⇒ Object

For CaseExpression, setting the default for an already build CaseExpression

API:

  • public



437
438
439
440
# File 'lib/puppet/pops/model/factory.rb', line 437

def default r
  current.addOptions(Puppet::Pops::Model::Factory.WHEN(:default, r).current)
  self
end

#dot(r) ⇒ Object

API:

  • public



394
# File 'lib/puppet/pops/model/factory.rb', line 394

def dot r;    f_build_binary(Model::NamedAccessExpression, current, r); end

#f_arithmetic(op, r) ⇒ Object

API:

  • public



363
364
365
# File 'lib/puppet/pops/model/factory.rb', line 363

def f_arithmetic(op, r)
  f_build_binary_op(Model::ArithmeticExpression, op, current, r)
end

#f_build_binary(klazz, left, right) ⇒ Object

API:

  • public



355
356
357
# File 'lib/puppet/pops/model/factory.rb', line 355

def f_build_binary(klazz, left, right)
  Puppet::Pops::Model::Factory.new(build(klazz.new, left, right))
end

#f_build_binary_op(klazz, op, left, right) ⇒ Object

API:

  • public



351
352
353
# File 'lib/puppet/pops/model/factory.rb', line 351

def f_build_binary_op(klazz, op, left, right)
  Puppet::Pops::Model::Factory.new(build(klazz.new, op, left, right))
end

#f_build_body(nothing) ⇒ Object #f_build_body(array) ⇒ Object #f_build_body(expr) ⇒ Object #f_build_body(obj) ⇒ Object

Builds body :) from different kinds of input

Overloads:

  • #f_build_body(nothing) ⇒ Object

    Parameters:

    • unchanged, produces nil

  • #f_build_body(array) ⇒ Object

    Parameters:

    • turns into a BlockExpression

  • #f_build_body(expr) ⇒ Object

    Parameters:

    • produces the given expression

  • #f_build_body(obj) ⇒ Object

    Parameters:

    • produces the result of calling #build with body as argument

API:

  • public



207
208
209
210
211
212
213
214
215
216
# File 'lib/puppet/pops/model/factory.rb', line 207

def f_build_body(body)
  case body
  when NilClass
    nil
  when Array
    Puppet::Pops::Model::Factory.new(Model::BlockExpression, *body)
  else
    build(body)
  end
end

#f_build_unary(klazz, expr) ⇒ Object

Puppet::Pops::Model::Factory helpers

API:

  • public



347
348
349
# File 'lib/puppet/pops/model/factory.rb', line 347

def f_build_unary(klazz, expr)
  Puppet::Pops::Model::Factory.new(build(klazz.new, expr))
end

#f_build_vararg(klazz, left, *arg) ⇒ Object

API:

  • public



359
360
361
# File 'lib/puppet/pops/model/factory.rb', line 359

def f_build_vararg(klazz, left, *arg)
  Puppet::Pops::Model::Factory.new(build(klazz.new, left, *arg))
end

#f_comparison(op, r) ⇒ Object

API:

  • public



367
368
369
# File 'lib/puppet/pops/model/factory.rb', line 367

def f_comparison(op, r)
  f_build_binary_op(Model::ComparisonExpression, op, current, r)
end

#f_match(op, r) ⇒ Object

API:

  • public



371
372
373
# File 'lib/puppet/pops/model/factory.rb', line 371

def f_match(op, r)
  f_build_binary_op(Model::MatchExpression, op, current, r)
end

#in(r) ⇒ Object

Operator helpers

API:

  • public



376
# File 'lib/puppet/pops/model/factory.rb', line 376

def in(r)     f_build_binary(Model::InExpression, current, r);          end

#interpolateObject

Polymorphic interpolate

API:

  • public



45
46
47
48
49
50
51
52
# File 'lib/puppet/pops/model/factory.rb', line 45

def interpolate()
  begin
    @@interpolation_visitor.visit_this_0(self, current)
  rescue =>e
    # debug here when in trouble...
    raise e
  end
end

#interpolate_AccessExpression(o) ⇒ Object

rewrite left expression to variable if it is name, number, and recurse if it is an access expression this is for interpolation support in new lexer ($NAME, $NAME[}, $NUMBER, $NUMBER[] - all other expressions requires variables to be preceded with $

API:

  • public



976
977
978
979
980
981
# File 'lib/puppet/pops/model/factory.rb', line 976

def interpolate_AccessExpression(o)
  if is_interop_rewriteable?(o.left_expr)
    o.left_expr = to_ops(self.class.new(o.left_expr).interpolate)
  end
  o
end

#interpolate_CallMethodExpression(o) ⇒ Object

Rewrite method calls on the form $… to $Puppet::Pops::Model::Factory.$x$x.each

API:

  • public



991
992
993
994
995
996
# File 'lib/puppet/pops/model/factory.rb', line 991

def interpolate_CallMethodExpression(o)
  if is_interop_rewriteable?(o.functor_expr)
    o.functor_expr = to_ops(self.class.new(o.functor_expr).interpolate)
  end
  o
end

#interpolate_Factory(o) ⇒ Object

API:

  • public



955
956
957
# File 'lib/puppet/pops/model/factory.rb', line 955

def interpolate_Factory(o)
  interpolate(o.current)
end

#interpolate_LiteralInteger(o) ⇒ Object

API:

  • public



959
960
961
962
# File 'lib/puppet/pops/model/factory.rb', line 959

def interpolate_LiteralInteger(o)
  # convert number to a variable
  self.class.new(o).var
end

#interpolate_NamedAccessExpression(o) ⇒ Object

API:

  • public



983
984
985
986
987
988
# File 'lib/puppet/pops/model/factory.rb', line 983

def interpolate_NamedAccessExpression(o)
  if is_interop_rewriteable?(o.left_expr)
      o.left_expr = to_ops(self.class.new(o.left_expr).interpolate)
  end
  o
end

#interpolate_Object(o) ⇒ Object

API:

  • public



964
965
966
# File 'lib/puppet/pops/model/factory.rb', line 964

def interpolate_Object(o)
  o
end

#interpolate_QualifiedName(o) ⇒ Object

API:

  • public



968
969
970
# File 'lib/puppet/pops/model/factory.rb', line 968

def interpolate_QualifiedName(o)
  self.class.new(o).var
end

#is_interop_rewriteable?(o) ⇒ Boolean

Returns:

API:

  • public



998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
# File 'lib/puppet/pops/model/factory.rb', line 998

def is_interop_rewriteable?(o)
  case o
  when Model::AccessExpression, Model::QualifiedName,
    Model::NamedAccessExpression, Model::CallMethodExpression
    true
  when Model::LiteralInteger
    # Only decimal integers can represent variables, else it is a number
    o.radix == 10
  else
    false
  end
end

#lambda=(lambda) ⇒ Object

API:

  • public



442
443
444
445
# File 'lib/puppet/pops/model/factory.rb', line 442

def lambda=(lambda)
  current.lambda = lambda.current
  self
end

#locPuppet::Pops::Adapters::SourcePosAdapter

Returns with location information.

Returns:

  • with location information

API:

  • public



498
499
500
# File 'lib/puppet/pops/model/factory.rb', line 498

def loc()
  Puppet::Pops::Adapters::SourcePosAdapter.adapt(current)
end

#minusObject

API:

  • public



384
# File 'lib/puppet/pops/model/factory.rb', line 384

def minus();  f_build_unary(Model::UnaryMinusExpression, self);         end

#minus_set(r) ⇒ Object

Assignment -=

API:

  • public



458
459
460
# File 'lib/puppet/pops/model/factory.rb', line 458

def minus_set(r)
  f_build_binary_op(Model::AssignmentExpression, :'-=', current, r)
end

#mne(r) ⇒ Object

API:

  • public



424
# File 'lib/puppet/pops/model/factory.rb', line 424

def mne r;    f_match(:'!~', r);                                        end

#name_is_statement(name) ⇒ Object

Returns true if the given name is a “statement keyword” (require, include, contain, error, notice, info, debug

API:

  • public



784
785
786
# File 'lib/puppet/pops/model/factory.rb', line 784

def name_is_statement(name)
  STATEMENT_CALLS[name]
end

#ne(r) ⇒ Object

API:

  • public



420
# File 'lib/puppet/pops/model/factory.rb', line 420

def ne r;     f_comparison(:'!=', r);                                   end

#notObject

API:

  • public



382
# File 'lib/puppet/pops/model/factory.rb', line 382

def not();    f_build_unary(Model::NotExpression, self);                end

#or(r) ⇒ Object

API:

  • public



378
# File 'lib/puppet/pops/model/factory.rb', line 378

def or(r)     f_build_binary(Model::OrExpression, current, r);          end

#parenObject

API:

  • public



426
# File 'lib/puppet/pops/model/factory.rb', line 426

def paren();  f_build_unary(Model::ParenthesizedExpression, current);   end

#plus_set(r) ⇒ Object

Assignment +=

API:

  • public



453
454
455
# File 'lib/puppet/pops/model/factory.rb', line 453

def plus_set(r)
  f_build_binary_op(Model::AssignmentExpression, :'+=', current, r)
end

#record_position(start_locatable, end_locatable) ⇒ Object

Records the position (start -> end) and computes the resulting length.

API:

  • public



486
487
488
489
490
491
492
493
494
495
# File 'lib/puppet/pops/model/factory.rb', line 486

def record_position(start_locatable, end_locatable)
  from = start_locatable.is_a?(Puppet::Pops::Model::Factory) ? start_locatable.current : start_locatable
  to   = end_locatable.is_a?(Puppet::Pops::Model::Factory) ? end_locatable.current  : end_locatable
  to = from if to.nil? || to.offset.nil?
  o = current
  # record information directly in the Model::Positioned object
  o.offset = from.offset
  o.length ||= to.offset - from.offset + to.length
  self
end

#relop(op, r) ⇒ Object

API:

  • public



428
429
430
# File 'lib/puppet/pops/model/factory.rb', line 428

def relop op, r
  f_build_binary_op(Model::RelationshipExpression, op.to_sym, current, r)
end

#respond_to?(meth, include_all = false) ⇒ Boolean

Returns:

API:

  • public



476
477
478
# File 'lib/puppet/pops/model/factory.rb', line 476

def respond_to?(meth, include_all=false)
  current.respond_to?(meth, include_all) || super
end

#select(*args) ⇒ Object

API:

  • public



432
433
434
# File 'lib/puppet/pops/model/factory.rb', line 432

def select *args
  Puppet::Pops::Model::Factory.new(build(Model::SelectorExpression, current, *args))
end

#set(r) ⇒ Object

Assignment =

API:

  • public



448
449
450
# File 'lib/puppet/pops/model/factory.rb', line 448

def set(r)
  f_build_binary_op(Model::AssignmentExpression, :'=', current, r)
end

#textObject

API:

  • public



388
# File 'lib/puppet/pops/model/factory.rb', line 388

def text();   f_build_unary(Model::TextExpression, self);               end

#to_ops(o, *args) ⇒ Object

Checks if the object is already a model object, or build it

API:

  • public



1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
# File 'lib/puppet/pops/model/factory.rb', line 1012

def to_ops(o, *args)
  case o
  when Model::PopsObject
    o
  when Puppet::Pops::Model::Factory
    o.current
  else
    build(o, *args)
  end
end

#to_sObject

API:

  • public



1037
1038
1039
# File 'lib/puppet/pops/model/factory.rb', line 1037

def to_s
  Puppet::Pops::Model::ModelTreeDumper.new.dump(self)
end

#type_expr(o) ⇒ Object

Set Expression that should evaluate to the parameter’s type

API:

  • public



595
596
597
# File 'lib/puppet/pops/model/factory.rb', line 595

def type_expr(o)
  current.type_expr = to_ops(o)
end

#unfoldObject

API:

  • public



386
# File 'lib/puppet/pops/model/factory.rb', line 386

def unfold(); f_build_unary(Model::UnfoldExpression, self);             end

#varObject

API:

  • public



390
# File 'lib/puppet/pops/model/factory.rb', line 390

def var();    f_build_unary(Model::VariableExpression, self);           end