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.'.freeze
DEFAULT_MSG =
'Prefer `numeric` over `symbolic` ' \
'to define HTTP status code.'.freeze
WHITELIST_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.



147
148
149
# File 'lib/rubocop/cop/rails/http_status.rb', line 147

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



146
147
148
# File 'lib/rubocop/cop/rails/http_status.rb', line 146

def node
  @node
end

Instance Method Details

#messageObject



155
156
157
158
159
160
161
# File 'lib/rubocop/cop/rails/http_status.rb', line 155

def message
  if RACK_LOADED
    format(MSG, prefer: preferred_style, current: symbol.inspect)
  else
    DEFAULT_MSG
  end
end

#offensive?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/rubocop/cop/rails/http_status.rb', line 151

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

#preferred_styleObject



163
164
165
# File 'lib/rubocop/cop/rails/http_status.rb', line 163

def preferred_style
  number.to_s
end