Class: Dao::Errors::KeyPrefixer

Inherits:
Object
  • Object
show all
Defined in:
lib/dao/errors.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ KeyPrefixer

Returns a new instance of KeyPrefixer.



266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/dao/errors.rb', line 266

def initialize(object)
  @object = object

  @prefix =
    if @object && @object.respond_to?(:model_name)
      @object.model_name.to_s.underscore
    else
      nil
    end

  @global = Array(Global)
end

Instance Attribute Details

#globalObject

Returns the value of attribute global.



264
265
266
# File 'lib/dao/errors.rb', line 264

def global
  @global
end

#objectObject

Returns the value of attribute object.



263
264
265
# File 'lib/dao/errors.rb', line 263

def object
  @object
end

Instance Method Details

#prefix(key) ⇒ Object



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
# File 'lib/dao/errors.rb', line 279

def prefix(key)
  is_global_key = key == @global || Array(key) == @global

  if @prefix
    if is_global_key
      @prefix
    else
      ["#{ @prefix }.#{ key[0] }", *key[1..-1]]
    end
  else
    if is_global_key
      'global'
    else
      key
    end
  end
end