Class: RuboCop::Cop::Rails::HttpStatus::NumericStyleChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/rails/http_status.rb

Overview

:nodoc:

Constant Summary collapse

MSG =
'Prefer `%<prefer>s` over `%<current>s` ' \
'to define HTTP status code.'
DEFAULT_MSG =
'Prefer `numeric` over `symbolic` ' \
'to define HTTP status code.'
PERMITTED_STATUS =
%i[error success missing redirect].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ NumericStyleChecker

Returns a new instance of NumericStyleChecker.



129
130
131
# File 'lib/rubocop/cop/rails/http_status.rb', line 129

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



127
128
129
# File 'lib/rubocop/cop/rails/http_status.rb', line 127

def node
  @node
end

Instance Method Details

#messageObject



137
138
139
# File 'lib/rubocop/cop/rails/http_status.rb', line 137

def message
  format(MSG, prefer: preferred_style, current: symbol.inspect)
end

#offensive?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/rubocop/cop/rails/http_status.rb', line 133

def offensive?
  !node.int_type? && !permitted_symbol?
end

#preferred_styleObject



141
142
143
# File 'lib/rubocop/cop/rails/http_status.rb', line 141

def preferred_style
  number.to_s
end