Class: RuboCop::Cop::Rails::HttpStatus::SymbolicStyleChecker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ SymbolicStyleChecker

Returns a new instance of SymbolicStyleChecker.



102
103
104
# File 'lib/rubocop/cop/rails/http_status.rb', line 102

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



101
102
103
# File 'lib/rubocop/cop/rails/http_status.rb', line 101

def node
  @node
end

Instance Method Details

#messageObject



110
111
112
113
114
115
116
# File 'lib/rubocop/cop/rails/http_status.rb', line 110

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

#offensive?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/rubocop/cop/rails/http_status.rb', line 106

def offensive?
  !node.sym_type? && !custom_http_status_code?
end

#preferred_styleObject



118
119
120
# File 'lib/rubocop/cop/rails/http_status.rb', line 118

def preferred_style
  symbol.inspect
end