Class: ConfigDSL::LazyValue
- Inherits:
-
Object
- Object
- ConfigDSL::LazyValue
- Defined in:
- lib/configdsl.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #cached? ⇒ Boolean
- #caching? ⇒ Boolean
- #flush_cache! ⇒ Object
-
#initialize(block, args = [], options = {}) ⇒ LazyValue
constructor
A new instance of LazyValue.
- #value(new_args = nil) ⇒ Object
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 = [], = {}) @block = block @args = args @options = self.class..merge() @cached = false end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
223 224 225 |
# File 'lib/configdsl.rb', line 223 def args @args end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
223 224 225 |
# File 'lib/configdsl.rb', line 223 def block @block end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
223 224 225 |
# File 'lib/configdsl.rb', line 223 def @options end |
Class Method Details
.default_options ⇒ Object
217 218 219 220 221 |
# File 'lib/configdsl.rb', line 217 def self. { caching: true } end |
Instance Method Details
#cached? ⇒ Boolean
251 252 253 |
# File 'lib/configdsl.rb', line 251 def cached? @cached end |
#caching? ⇒ Boolean
242 243 244 |
# File 'lib/configdsl.rb', line 242 def caching? !![: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 |