Class: InvalidModel::Error

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(errors_object, attribute, type, meta) ⇒ Error

Returns a new instance of Error.



9
10
11
12
13
14
# File 'lib/invalid_model/error.rb', line 9

def initialize(errors_object, attribute, type, meta)
  @errors_object = errors_object
  @attribute = attribute
  @type = type
  @meta = meta
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



7
8
9
# File 'lib/invalid_model/error.rb', line 7

def attribute
  @attribute
end

#errors_objectObject (readonly)

Returns the value of attribute errors_object.



7
8
9
# File 'lib/invalid_model/error.rb', line 7

def errors_object
  @errors_object
end

#metaObject (readonly)

Returns the value of attribute meta.



7
8
9
# File 'lib/invalid_model/error.rb', line 7

def meta
  @meta
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/invalid_model/error.rb', line 7

def type
  @type
end

Class Method Details

.from_hash(errors_object, attribute, hash) ⇒ Object



3
4
5
# File 'lib/invalid_model/error.rb', line 3

def self.from_hash(errors_object, attribute, hash)
  new(errors_object, attribute, hash[:error], hash.except(:error))
end

Instance Method Details

#detailObject



16
17
18
# File 'lib/invalid_model/error.rb', line 16

def detail
  @errors_object.full_message(attribute, errors_object.generate_message(attribute, type, meta))
end

#model_nameObject



20
21
22
# File 'lib/invalid_model/error.rb', line 20

def model_name
  errors_object.instance_variable_get(:@base).model_name
end