Class: LittleBoxes::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/little_boxes/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, eager:, memo:, box:, block:, configure:, then_block:) ⇒ Entry

Returns a new instance of Entry.



5
6
7
8
9
10
11
12
13
14
# File 'lib/little_boxes/entry.rb', line 5

def initialize(name:, eager:, memo:, box:, block:, configure:, then_block:)
  self.name = name
  self.memo = memo
  self.box = box
  self.eager = eager
  self.configure = configure
  self.then_block = then_block
  self.block = block
  self.mutex = Mutex.new if @memo
end

Instance Attribute Details

#blockObject

Returns the value of attribute block.



3
4
5
# File 'lib/little_boxes/entry.rb', line 3

def block
  @block
end

#boxObject

Returns the value of attribute box.



3
4
5
# File 'lib/little_boxes/entry.rb', line 3

def box
  @box
end

#configureObject

Returns the value of attribute configure.



3
4
5
# File 'lib/little_boxes/entry.rb', line 3

def configure
  @configure
end

#eagerObject

Returns the value of attribute eager.



3
4
5
# File 'lib/little_boxes/entry.rb', line 3

def eager
  @eager
end

#memoObject

Returns the value of attribute memo.



3
4
5
# File 'lib/little_boxes/entry.rb', line 3

def memo
  @memo
end

#mutexObject

Returns the value of attribute mutex.



3
4
5
# File 'lib/little_boxes/entry.rb', line 3

def mutex
  @mutex
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/little_boxes/entry.rb', line 3

def name
  @name
end

#then_blockObject

Returns the value of attribute then_block.



3
4
5
# File 'lib/little_boxes/entry.rb', line 3

def then_block
  @then_block
end

Instance Method Details

#valueObject



16
17
18
19
20
21
22
# File 'lib/little_boxes/entry.rb', line 16

def value
  if @memo
    @mutex.synchronize { @block.call(@box) }
  else
    @block.call(@box)
  end
end