Parent

Methods

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Rails::ReadWriteAttribute

This cop checks for the use of the read_attribute or write_attribute methods.

@example

# bad
x = read_attributed(:attr)
write_attribute(:attr, val)

# good
x = self[:attr]
self[:attr] = val

Constants

MSG

Public Instance Methods

message(node) click to toggle source
# File lib/rubocop/cop/rails/read_write_attribute.rb, line 29
def message(node)
  _receiver, method_name, *_args = *node

  if method_name == :read_attribute
    format(MSG, 'self[:attr]', 'read_attribute(:attr)')
  else
    format(MSG, 'self[:attr] = val', 'write_attribute(:attr, var)')
  end
end
on_send(node) click to toggle source
# File lib/rubocop/cop/rails/read_write_attribute.rb, line 20
def on_send(node)
  receiver, method_name, *_args = *node
  return if receiver
  return unless [:read_attribute,
                 :write_attribute].include?(method_name)

  add_offense(node, :selector)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.