class RuboCop::Cop::Chef::Correctness::LazyEvalNodeAttributeDefaults
When setting a node attribute as the default value for a custom resource property, wrap the node attribute in ‘lazy {}` so that its value is available when the resource executes.
@example
### incorrect property :Something, String, default: node['hostname'] ### correct property :Something, String, default: lazy { node['hostname'] }
Constants
- MSG
Public Instance Methods
Source
# File lib/rubocop/cop/chef/correctness/lazy_eval_node_attribute_defaults.rb, line 42 def on_send(node) non_lazy_node_attribute_default?(node) do |default| add_offense(default, severity: :refactor) do |corrector| corrector.replace(default, "lazy { #{default.source} }") end end end