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.
220 221 222 223 224 225 |
# File 'lib/configdsl.rb', line 220 def initialize(block, args = [], = {}) @block = block @args = args = self.class..merge() @cached = false end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
218 219 220 |
# File 'lib/configdsl.rb', line 218 def args @args end |
#block ⇒ Object (readonly)
Returns the value of attribute block.
218 219 220 |
# File 'lib/configdsl.rb', line 218 def block @block end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
218 219 220 |
# File 'lib/configdsl.rb', line 218 def end |
Class Method Details
.default_options ⇒ Object
212 213 214 215 216 |
# File 'lib/configdsl.rb', line 212 def self. { caching: true } end |
Instance Method Details
#cached? ⇒ Boolean
246 247 248 |
# File 'lib/configdsl.rb', line 246 def cached? @cached end |
#caching? ⇒ Boolean
237 238 239 |
# File 'lib/configdsl.rb', line 237 def caching? !![:caching] end |
#flush_cache! ⇒ Object
241 242 243 244 |
# File 'lib/configdsl.rb', line 241 def flush_cache! @cache = nil # clean pointer so that GC can do it's work immediately @cached = true end |
#value(new_args = nil) ⇒ Object
227 228 229 230 231 232 233 234 235 |
# File 'lib/configdsl.rb', line 227 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 |