class RuboCop::Cop::Infinum::AttributeDefaultBlockValue
This cop looks for `attribute` class methods that specify a `:default` option and pass it a method without a block.
@example
# bad class User < ApplicationRecord attribute :confirmed_at, :datetime, default: Time.zone.now end # good class User < ActiveRecord::Base attribute :confirmed_at, :datetime, default: -> { Time.zone.now } end
Constants
- MSG
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/infinum/attribute_default_block_value.rb, line 38 def autocorrect(node) expression = default_attribute(node).children.last lambda do |corrector| corrector.replace(expression, "-> { #{expression.source} }") end end
on_send(node)
click to toggle source
# File lib/rubocop/cop/infinum/attribute_default_block_value.rb, line 30 def on_send(node) default_attribute(node) do |attribute| value = attribute.children.last add_offense(node, location: value) if value.send_type? end end