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

Defined Under Namespace

Classes: ArgsToNonCallError

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,
  'err'     => 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



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

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



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

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

.ATTRIBUTE_OP(name, op, expr) ⇒ Object

API:

  • public



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

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

.ATTRIBUTES_OP(expr) ⇒ Object

API:

  • public



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

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

.block(*args) ⇒ Object

API:

  • public



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

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



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

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



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

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



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

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



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

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

.COLLECT(type_expr, query_expr, attribute_operations) ⇒ Object

API:

  • public



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

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

.concat(*args) ⇒ Object

API:

  • public



1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
# File 'lib/puppet/pops/model/factory.rb', line 1039

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



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

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

.ENUM(*args) ⇒ Object

API:

  • public



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

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

.EPP(parameters, body) ⇒ Object

API:

  • public



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

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



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

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



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

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



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

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



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

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

.HEREDOC(name, expr) ⇒ Object

API:

  • public



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

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

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

API:

  • public



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

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



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

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



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

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

.LAMBDA(parameters, body) ⇒ Object

API:

  • public



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

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

.LIST(entries) ⇒ Object

API:

  • public



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

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

.literal(o) ⇒ Object

Factory starting points

API:

  • public



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

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

.MAP(match, value) ⇒ Object

API:

  • public



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

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

.minus(o) ⇒ Object

API:

  • public



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

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

.NAMED_ACCESS(type_name, bodies) ⇒ Object

API:

  • public



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

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

.NODE(hosts, parent, body) ⇒ Object

API:

  • public



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

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

.nop?(o) ⇒ Boolean

Returns:

API:

  • public



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

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

.NUMBER(name_or_numeric) ⇒ Object

API:

  • public



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

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



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

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

.PROGRAM(body, definitions, locator) ⇒ Object

API:

  • public



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

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



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

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



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

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



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

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

.record_position(o, start_locatable, end_locateable) ⇒ Object

API:

  • public



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

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

.RENDER_EXPR(expr) ⇒ Object

API:

  • public



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

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

.RENDER_STRING(o) ⇒ Object

TODO_EPP

API:

  • public



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

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

.RESERVED(name, future = false) ⇒ Object

API:

  • public



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

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

.RESOURCE(type_name, bodies) ⇒ Object

API:

  • public



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

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

.RESOURCE_BODY(resource_title, attribute_operations) ⇒ Object

API:

  • public



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

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



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

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



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

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



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

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



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

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



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

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

.SUBLOCATE(token, expr) ⇒ Object

API:

  • public



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

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

.TEXT(expr) ⇒ Object

API:

  • public



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

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

.text(o) ⇒ Object

API:

  • public



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

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



800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
# File 'lib/puppet/pops/model/factory.rb', line 800

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]
      if expr.is_a?(Array)
        expr = expr.reject {|e| e.is_a?(Puppet::Pops::Parser::LexerSupport::TokenValue) }
      else
        expr = [expr]
      end
      the_call = Puppet::Pops::Model::Factory.CALL_NAMED(name, false, 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
    elsif expr.is_a?(Array)
      raise ArgsToNonCallError.new(expr, name)
    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



837
838
839
840
841
842
843
844
845
846
847
# File 'lib/puppet/pops/model/factory.rb', line 837

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



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

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

.unfold(o) ⇒ Object

API:

  • public



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

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

.UNLESS(test_e, then_e, else_e) ⇒ Object

API:

  • public



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

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

.var(o) ⇒ Object

API:

  • public



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

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

.VIRTUAL_QUERY(query_expr) ⇒ Object

API:

  • public



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

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

.WHEN(values_list, block) ⇒ Object

API:

  • public



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

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

Instance Method Details

#%(r) ⇒ Object

API:

  • public



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

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

#*(r) ⇒ Object

API:

  • public



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

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

#+(r) ⇒ Object

API:

  • public



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

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

#-(r) ⇒ Object

API:

  • public



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

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

#/(r) ⇒ Object

API:

  • public



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

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

#<(r) ⇒ Object

API:

  • public



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

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

#<<(r) ⇒ Object

API:

  • public



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

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

#<=(r) ⇒ Object

API:

  • public



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

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

#==(r) ⇒ Object

API:

  • public



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

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

#=~(r) ⇒ Object

API:

  • public



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

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

#>(r) ⇒ Object

API:

  • public



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

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

#>=(r) ⇒ Object

API:

  • public



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

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

#>>(r) ⇒ Object

API:

  • public



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

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

#[](*r) ⇒ Object

API:

  • public



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

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

#and(r) ⇒ Object

API:

  • public



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

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

#attributes(*args) ⇒ Object

API:

  • public



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

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



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

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



938
939
940
941
942
943
# File 'lib/puppet/pops/model/factory.rb', line 938

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



945
946
947
948
949
# File 'lib/puppet/pops/model/factory.rb', line 945

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



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

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



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

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



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

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



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

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



903
904
905
# File 'lib/puppet/pops/model/factory.rb', line 903

def build_Factory(o)
  o.current
end

#build_FalseClass(o) ⇒ Object

API:

  • public



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

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

#build_Fixnum(o) ⇒ Object

API:

  • public



877
878
879
880
881
# File 'lib/puppet/pops/model/factory.rb', line 877

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

#build_Float(o) ⇒ Object

API:

  • public



883
884
885
886
887
# File 'lib/puppet/pops/model/factory.rb', line 883

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



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

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



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

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



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

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



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

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



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

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

#build_LiteralHash(o, *keyed_entries) ⇒ Object

API:

  • public



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

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

#build_LiteralInteger(o, val, radix) ⇒ Object

API:

  • public



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

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

#build_LiteralList(o, *values) ⇒ Object

API:

  • public



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

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

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

API:

  • public



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

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



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

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



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

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

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

Parameters:

API:

  • public



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

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



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

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



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

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



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

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

#build_QualifiedReference(o, name) ⇒ Object

API:

  • public



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

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

#build_QueryExpression(o, expr) ⇒ Object

API:

  • public



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

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



889
890
891
892
893
# File 'lib/puppet/pops/model/factory.rb', line 889

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

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

API:

  • public



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

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

#build_RenderStringExpression(o, string) ⇒ Object

API:

  • public



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

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

#build_ReservedWord(o, name, future) ⇒ Object

API:

  • public



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

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

#build_ResourceBody(o, title_expression, attribute_operations) ⇒ Object

API:

  • public



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

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



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

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



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

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



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

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



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

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



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

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



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

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



910
911
912
913
914
915
916
917
918
919
# File 'lib/puppet/pops/model/factory.rb', line 910

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



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

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



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

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

#build_UnaryExpression(o, expr) ⇒ Object

API:

  • public



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

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



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

def captures_rest()
  current.captures_rest = true
end

#default(r) ⇒ Object

For CaseExpression, setting the default for an already build CaseExpression

API:

  • public



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

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

#dot(r) ⇒ Object

API:

  • public



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

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

#f_arithmetic(op, r) ⇒ Object

API:

  • public



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

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

#f_build_binary(klazz, left, right) ⇒ Object

API:

  • public



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

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



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

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



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

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



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

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



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

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



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

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

#f_match(op, r) ⇒ Object

API:

  • public



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

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

#in(r) ⇒ Object

Operator helpers

API:

  • public



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

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



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

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



1007
1008
1009
1010
1011
1012
# File 'lib/puppet/pops/model/factory.rb', line 1007

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



971
972
973
# File 'lib/puppet/pops/model/factory.rb', line 971

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

#interpolate_LiteralInteger(o) ⇒ Object

API:

  • public



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

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

#interpolate_NamedAccessExpression(o) ⇒ Object

API:

  • public



999
1000
1001
1002
1003
1004
# File 'lib/puppet/pops/model/factory.rb', line 999

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



980
981
982
# File 'lib/puppet/pops/model/factory.rb', line 980

def interpolate_Object(o)
  o
end

#interpolate_QualifiedName(o) ⇒ Object

API:

  • public



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

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

#is_interop_rewriteable?(o) ⇒ Boolean

Returns:

API:

  • public



1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
# File 'lib/puppet/pops/model/factory.rb', line 1014

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



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

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

#locPuppet::Pops::Adapters::SourcePosAdapter

Returns with location information.

Returns:

  • with location information

API:

  • public



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

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

#minusObject

API:

  • public



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

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

#minus_set(r) ⇒ Object

Assignment -=

API:

  • public



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

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

#mne(r) ⇒ Object

API:

  • public



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

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



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

def name_is_statement(name)
  STATEMENT_CALLS[name]
end

#ne(r) ⇒ Object

API:

  • public



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

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

#notObject

API:

  • public



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

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

#or(r) ⇒ Object

API:

  • public



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

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

#parenObject

API:

  • public



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

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

#plus_set(r) ⇒ Object

Assignment +=

API:

  • public



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

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



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

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



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

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



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

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

#select(*args) ⇒ Object

API:

  • public



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

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

#set(r) ⇒ Object

Assignment =

API:

  • public



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

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

#textObject

API:

  • public



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

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



1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
# File 'lib/puppet/pops/model/factory.rb', line 1028

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



1053
1054
1055
# File 'lib/puppet/pops/model/factory.rb', line 1053

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



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

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

#unfoldObject

API:

  • public



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

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

#varObject

API:

  • public



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

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