Class: MDOT::ExceptionKey

Inherits:
Object
  • Object
show all
Defined in:
lib/mdot/exceptions/key.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ ExceptionKey

Returns a new instance of ExceptionKey.



7
8
9
10
11
# File 'lib/mdot/exceptions/key.rb', line 7

def initialize(key)
  @default_exception = 'default_exception'
  @key = validate_key(key)
  @i18n_key = "mdot.exceptions.#{@key}"
end

Instance Attribute Details

#i18n_keyObject (readonly)

Returns the value of attribute i18n_key.



5
6
7
# File 'lib/mdot/exceptions/key.rb', line 5

def i18n_key
  @i18n_key
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/mdot/exceptions/key.rb', line 5

def key
  @key
end

Instance Method Details

#key_exists?(key) ⇒ Boolean (private)

Returns:

  • (Boolean)


15
16
17
# File 'lib/mdot/exceptions/key.rb', line 15

def key_exists?(key)
  I18n.exists?("mdot.exceptions.#{key}")
end

#validate_key(key) ⇒ Object (private)



19
20
21
# File 'lib/mdot/exceptions/key.rb', line 19

def validate_key(key)
  key.present? && key_exists?(key) ? key : @default_exception
end