Class: ConfigDSL::LazyValue

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(block, args = [], options = {}) ⇒ LazyValue

Returns a new instance of LazyValue.



225
226
227
228
229
230
# File 'lib/configdsl.rb', line 225

def initialize(block, args = [], options = {})
  @block = block
  @args = args
  @options = self.class.default_options.merge(options)
  @cached = false
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



223
224
225
# File 'lib/configdsl.rb', line 223

def args
  @args
end

#blockObject (readonly)

Returns the value of attribute block.



223
224
225
# File 'lib/configdsl.rb', line 223

def block
  @block
end

#optionsObject (readonly)

Returns the value of attribute options.



223
224
225
# File 'lib/configdsl.rb', line 223

def options
  @options
end

Class Method Details

.default_optionsObject



217
218
219
220
221
# File 'lib/configdsl.rb', line 217

def self.default_options
  {
    caching: true        
  }
end

Instance Method Details

#cached?Boolean

Returns:

  • (Boolean)


251
252
253
# File 'lib/configdsl.rb', line 251

def cached?
  @cached
end

#caching?Boolean

Returns:

  • (Boolean)


242
243
244
# File 'lib/configdsl.rb', line 242

def caching?
  !!options[:caching]
end

#flush_cache!Object



246
247
248
249
# File 'lib/configdsl.rb', line 246

def flush_cache!
  @cache = nil # clean pointer so that GC can do it's work immediately
  @cached = true
end

#value(new_args = nil) ⇒ Object



232
233
234
235
236
237
238
239
240
# File 'lib/configdsl.rb', line 232

def value(new_args = nil)
  return @cache if caching? && cached?
  value = block.call(*(new_args ? new_args : args))
  if caching?
    @cache = value
    @cached = true
  end
  value
end