Exception: QueryStream::UnknownKeyError

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

Overview

テンプレートに、データレコードが持たないキーが書かれている

「どのキーが無いか」だけでなく「代わりに何が使えるか」「どのファイルを直すか」まで 属性で渡す。呼び出し元はこれを使って「もしかして =author?」のような案内を組み立てられる。 属性が無かった頃はこのクラスだけが gem 内で logger.error を呼んでおり、 利用できるキーの一覧を呼び出し元が受け取れなかった。

location(記法の位置)と template_path(雛形の位置)は別物である。 直すのは雛形なので、記法の位置だけでは著者はファイルを開けない。

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = nil, key_path: nil, available_keys: [], template_path: nil, location: nil) ⇒ UnknownKeyError

Returns a new instance of UnknownKeyError.



71
72
73
74
75
76
77
# File 'lib/query_stream/errors.rb', line 71

def initialize(msg = nil, key_path: nil, available_keys: [], template_path: nil, location: nil)
  super(msg || "テンプレートに存在しないキーが記述されています: #{key_path}")
  @key_path       = key_path
  @available_keys = Array(available_keys)
  @template_path  = template_path
  @location       = location
end

Instance Attribute Details

#available_keysArray<Symbol> (readonly)

レコードが実際に持つキー

Returns:

  • (Array<Symbol>)

    the current value of available_keys



68
69
70
# File 'lib/query_stream/errors.rb', line 68

def available_keys
  @available_keys
end

#key_pathString (readonly)

テンプレートに書かれていたキー("author.name" 等)

Returns:

  • (String)

    the current value of key_path



68
69
70
# File 'lib/query_stream/errors.rb', line 68

def key_path
  @key_path
end

#locationString (readonly)

記法が書かれていたソースファイル名と行番号

Returns:

  • (String)

    the current value of location



68
69
70
# File 'lib/query_stream/errors.rb', line 68

def location
  @location
end

#template_pathString? (readonly)

打ち間違いがあるテンプレートのパス

Returns:

  • (String, nil)

    the current value of template_path



68
69
70
# File 'lib/query_stream/errors.rb', line 68

def template_path
  @template_path
end