Sha256: eba8b826137ca0540ff25cf01b2c17ab92b64e866ceb1dc36fcae6d99f815af2

Contents?: true

Size: 759 Bytes

Versions: 4

Compression:

Stored size: 759 Bytes

Contents

module Zygote
  # Provides a hook for identifiers to alter boot-time behavior
  # To do so, extend this class with a new identify method.
  # You may NOT define more than one identifier - the last one wins.
  # class MyIdentifier < Zygote::Identifier
  #   def identify
  #     mutate_params(@params)
  #   end
  # end
  class Identifier
    class << self
      def inherited(subclass)
        @identifier = subclass
      end

      def identify(params)
        @identifier ||= self
        @identifier.new(params).identify
      end

      def reset!
        @identifier = self
      end
    end

    def initialize(params)
      @params = params
    end

    # Called only if this class is never subclassed
    def identify
      @params
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zygote-0.2.15 lib/zygote/identifier.rb
zygote-0.2.14 lib/zygote/identifier.rb
zygote-0.2.13 lib/zygote/identifier.rb
zygote-0.2.12 lib/zygote/identifier.rb