Sha256: 66ce197a024101f427607b43de0991ac880a4fb21666d6195e85019226ffa9d9

Contents?: true

Size: 1.24 KB

Versions: 28

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

module Puppet::Pops
module Types
# Interface implemented by a type that has InvocableMembers
module TypeWithMembers
  # @return [InvocableMember,nil] An invocable member if it exists, or `nil`
  def [](member_name)
    raise NotImplementedError, "'#{self.class.name}' should implement #[]"
  end
end

# Interface implemented by attribute and function members
module InvocableMember
  # Performs type checking of arguments and invokes the method that corresponds to this
  # method. The result of the invocation is returned
  #
  # @param receiver [Object] The receiver of the call
  # @param scope [Puppet::Parser::Scope] The caller scope
  # @param args [Array] Array of arguments.
  # @return [Object] The result returned by the member function or attribute
  #
  # @api private
  def invoke(receiver, scope, args, &block)
    raise NotImplementedError, "'#{self.class.name}' should implement #invoke"
  end
end

# Plays the same role as an PAttribute in the PObjectType. Provides
# access to known attr_readers and plain reader methods.
class AttrReader
  include InvocableMember

  def initialize(message)
    @message = message.to_sym
  end

  def invoke(receiver, scope, args, &block)
    receiver.send(@message)
  end
end
end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/pops/types/type_with_members.rb
puppet-8.10.0-x86-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.10.0-x64-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.10.0-universal-darwin lib/puppet/pops/types/type_with_members.rb
puppet-8.9.0 lib/puppet/pops/types/type_with_members.rb
puppet-8.9.0-x86-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.9.0-x64-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.9.0-universal-darwin lib/puppet/pops/types/type_with_members.rb
puppet-8.8.1 lib/puppet/pops/types/type_with_members.rb
puppet-8.8.1-x86-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.8.1-x64-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.8.1-universal-darwin lib/puppet/pops/types/type_with_members.rb
puppet-8.7.0 lib/puppet/pops/types/type_with_members.rb
puppet-8.7.0-x86-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.7.0-x64-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.7.0-universal-darwin lib/puppet/pops/types/type_with_members.rb
puppet-8.6.0 lib/puppet/pops/types/type_with_members.rb
puppet-8.6.0-x86-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.6.0-x64-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.6.0-universal-darwin lib/puppet/pops/types/type_with_members.rb