Class: BulkLoader::Lazy

Inherits:
Object
  • Object
show all
Defined in:
lib/bulk_loader/lazy.rb

Overview

lazy class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, name: nil) ⇒ Lazy

Returns a new instance of Lazy.



10
11
12
13
14
15
# File 'lib/bulk_loader/lazy.rb', line 10

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

Instance Attribute Details

#targetObject (readonly)

Returns the value of attribute target.



8
9
10
# File 'lib/bulk_loader/lazy.rb', line 8

def target
  @target
end

Instance Method Details

#clearObject



28
29
30
31
# File 'lib/bulk_loader/lazy.rb', line 28

def clear
  @loaded = false
  @value = nil
end

#getObject

Raises:



17
18
19
20
21
# File 'lib/bulk_loader/lazy.rb', line 17

def get
  raise UnloadAccessError, "#{@name} has not been loaded!!" unless @loaded

  @value
end

#loaded?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/bulk_loader/lazy.rb', line 33

def loaded?
  @loaded
end

#set(value) ⇒ Object



23
24
25
26
# File 'lib/bulk_loader/lazy.rb', line 23

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