Class: Tobacco::Error

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Error

Returns a new instance of Error.



12
13
14
15
16
17
# File 'lib/tobacco/error.rb', line 12

def initialize(options = {})
  self.msg      = options[:msg]
  self.filepath = options[:filepath]
  self.content  = options[:content]
  self.object   = options[:object]
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



10
11
12
# File 'lib/tobacco/error.rb', line 10

def content
  @content
end

#filepathObject

Returns the value of attribute filepath.



10
11
12
# File 'lib/tobacco/error.rb', line 10

def filepath
  @filepath
end

#msgObject

Returns the value of attribute msg.



10
11
12
# File 'lib/tobacco/error.rb', line 10

def msg
  @msg
end

#objectObject

Returns the value of attribute object.



10
11
12
# File 'lib/tobacco/error.rb', line 10

def object
  @object
end

Instance Method Details

#to_aObject Also known as: to_ary

Allow destructure of the error into variable names

eg.

msg, filepath, content, object = *error
[ 'Error writing file', '/path/to/file', '<h1>Title</h1>', #<Errno::EACCES: Permission denied - /users/index.txt> ]

You can access the attributes normally as well

error.msg      #=> 'Error writing file'
error.filepath #=> '/path/to/file'
error.object   #=> #<Errno::EACCES: Permission denied - /users/index.txt>


32
33
34
# File 'lib/tobacco/error.rb', line 32

def to_a
  [ msg, filepath, content, object ]
end