Skip to content

Instantly share code, notes, and snippets.

@hlindberg
Last active January 30, 2020 15:52
Show Gist options
  • Select an option

  • Save hlindberg/e033ab9c8e20282cc494db6f04afc308 to your computer and use it in GitHub Desktop.

Select an option

Save hlindberg/e033ab9c8e20282cc494db6f04afc308 to your computer and use it in GitHub Desktop.

Revisions

  1. hlindberg revised this gist Jan 30, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    # The latch function remembers what it was called with
    # and returns what it was previous called with.
    # and returns what it was previously called with.
    #
    # This is using global namespace - in your code use a module namespace
    #
  2. hlindberg created this gist Jan 30, 2020.
    28 changes: 28 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # The latch function remembers what it was called with
    # and returns what it was previous called with.
    #
    # This is using global namespace - in your code use a module namespace
    #
    Puppet::Functions.create_function(:latch) do
    dispatch :example do
    repeated_param 'Any', :arg
    end

    def example(*args)
    adapter = adapterclass.adapt(closure_scope().compiler)
    result = adapter.thing
    adapter.thing = args
    result
    end

    def adapterclass
    @adapterclass ||= Class.new(Puppet::Pops::Adaptable::Adapter) do
    attr_accessor :thing
    def self.name()
    # This is using global namespace - in your code use a module namespace
    "LatchFunctionAdapter"
    end
    end
    @adapterclass
    end
    end