Class: RailsBestPractices::Core::Error

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_best_practices/core/error.rb

Overview

Error is the violation to rails best practice.

it indicates the filenname, line number and error message for the violation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Error

Returns a new instance of Error.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rails_best_practices/core/error.rb', line 11

def initialize(options={})
  @filename = options[:filename]
  @line_number = options[:line_number].to_s
  @message = options[:message]
  @type = options[:type]
  @url = options[:url]
  @git_commit = options[:git_commit]
  @git_username = options[:git_username]
  @hg_commit = options[:hg_commit]
  @hg_username = options[:hg_username]
end

Instance Attribute Details

#filename ⇒ Object (readonly)

Returns the value of attribute filename.



8
9
10
# File 'lib/rails_best_practices/core/error.rb', line 8

def filename
  @filename
end

#git_commit ⇒ Object

Returns the value of attribute git_commit.



9
10
11
# File 'lib/rails_best_practices/core/error.rb', line 9

def git_commit
  @git_commit
end

#git_username ⇒ Object

Returns the value of attribute git_username.



9
10
11
# File 'lib/rails_best_practices/core/error.rb', line 9

def git_username
  @git_username
end

#hg_commit ⇒ Object

Returns the value of attribute hg_commit.



9
10
11
# File 'lib/rails_best_practices/core/error.rb', line 9

def hg_commit
  @hg_commit
end

#hg_username ⇒ Object

Returns the value of attribute hg_username.



9
10
11
# File 'lib/rails_best_practices/core/error.rb', line 9

def hg_username
  @hg_username
end

#line_number ⇒ Object (readonly)

Returns the value of attribute line_number.



8
9
10
# File 'lib/rails_best_practices/core/error.rb', line 8

def line_number
  @line_number
end

#message ⇒ Object (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/rails_best_practices/core/error.rb', line 8

def message
  @message
end

#type ⇒ Object (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/rails_best_practices/core/error.rb', line 8

def type
  @type
end

#url ⇒ Object (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/rails_best_practices/core/error.rb', line 8

def url
  @url
end

Instance Method Details

#first_line_number ⇒ Object



27
28
29
# File 'lib/rails_best_practices/core/error.rb', line 27

def first_line_number
  line_number.split(',').first
end

#short_filename ⇒ Object



23
24
25
# File 'lib/rails_best_practices/core/error.rb', line 23

def short_filename
  File.expand_path(filename)[File.expand_path(Core::Runner.base_path).size..-1].sub(/^\//, '')
end

#to_s ⇒ Object



31
32
33
# File 'lib/rails_best_practices/core/error.rb', line 31

def to_s
  "#{@filename}:#{@line_number} - #{@message}"
end