Class: Configatron::Proc

Inherits:
Object
  • Object
show all
Defined in:
lib/configatron/proc.rb

Direct Known Subclasses

Delayed, Dynamic

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Proc


8
9
10
11
# File 'lib/configatron/proc.rb', line 8

def initialize(&block)
  self.execution_count = 0
  self.block = block
end

Instance Attribute Details

#blockObject

Returns the value of attribute block


6
7
8
# File 'lib/configatron/proc.rb', line 6

def block
  @block
end

#execution_countObject

Returns the value of attribute execution_count


5
6
7
# File 'lib/configatron/proc.rb', line 5

def execution_count
  @execution_count
end

Instance Method Details

#callObject


13
14
15
16
17
18
19
20
21
22
# File 'lib/configatron/proc.rb', line 13

def call
  unless @val
    val = self.block.call
    self.execution_count += 1
    if finalize?
      @val = val
    end
  end
  return val || @val
end

#finalize?Boolean


24
25
26
# File 'lib/configatron/proc.rb', line 24

def finalize?
  true
end

#inspectObject


28
29
30
# File 'lib/configatron/proc.rb', line 28

def inspect
  call.inspect
end