Class: Maini::Error

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

Instance Method Summary collapse

Constructor Details

#initialize(type, message, custom_json = nil) ⇒ Error

Returns a new instance of Error.



6
7
8
9
10
# File 'lib/maini/utils/error.rb', line 6

def initialize(type, message, custom_json = nil)
  @type     = type
  @message  = I18n.t("maini.errors.#{type}", :default => message)
  @custom_json = custom_json
end

Instance Method Details

#to_json(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/maini/utils/error.rb', line 12

def to_json(options={})
  @obj = {:errors => { @type => [@message] }}

  if @custom_json
    @obj[:errors][@type] = [@message,@custom_json]
  end

  @obj.to_json
end