Sha256: 4168f5e2c7c9d652821489c5cb7205eb62d16bc0939d1921e295688c22172559

Contents?: true

Size: 1.24 KB

Versions: 20

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

20 entries across 20 versions & 1 rubygems

Version Path
puppet-8.3.0 lib/puppet/pops/types/type_with_members.rb
puppet-8.3.0-x86-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.3.0-x64-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.3.0-universal-darwin lib/puppet/pops/types/type_with_members.rb
puppet-8.3.1 lib/puppet/pops/types/type_with_members.rb
puppet-8.3.1-x86-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.3.1-x64-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.3.1-universal-darwin lib/puppet/pops/types/type_with_members.rb
puppet-8.2.0 lib/puppet/pops/types/type_with_members.rb
puppet-8.2.0-x86-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.2.0-x64-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.2.0-universal-darwin lib/puppet/pops/types/type_with_members.rb
puppet-8.1.0 lib/puppet/pops/types/type_with_members.rb
puppet-8.1.0-x86-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.1.0-x64-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.1.0-universal-darwin lib/puppet/pops/types/type_with_members.rb
puppet-8.0.1 lib/puppet/pops/types/type_with_members.rb
puppet-8.0.1-x86-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.0.1-x64-mingw32 lib/puppet/pops/types/type_with_members.rb
puppet-8.0.1-universal-darwin lib/puppet/pops/types/type_with_members.rb