Sha256: ff97b15c8aa04b20b52c40542cd30aa9eb6668257593615b32942bb4b3f06330

Contents?: true

Size: 468 Bytes

Versions: 2

Compression:

Stored size: 468 Bytes

Contents

# frozen_string_literal: true

module BulkLoader
  # lazy class
  class Lazy
    attr_reader :target

    def initialize(target)
      @loaded = false
      @value = nil
      @target = target
    end

    def get
      raise 'data is not loaded!!' unless @loaded
      @value
    end

    def set(value)
      @loaded = true
      @value = value
    end

    def clear
      @loaded = false
      @value = nil
    end

    def loaded?
      @loaded
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bulk_loader-0.2.0 lib/bulk_loader/lazy.rb
bulk_loader-0.1.0 lib/bulk_loader/lazy.rb