Class: SiteSettingHandler
- Inherits:
-
Object
- Object
- SiteSettingHandler
- Defined in:
- lib/sitesettinghandler.rb
Direct Known Subclasses
Defined Under Namespace
Classes: PseudoMatchData
Constant Summary collapse
- HANDLER_DIR =
"handler"- HANDLER_EXT =
".rb"- @@klasses =
{}
Class Attribute Summary collapse
-
.type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- ._make_handler(parent, type, value) ⇒ Object
-
.add_handler(path_or_type: @@current_path, klass: self) ⇒ Object
ハンドラを登録する.
-
.handler(parent, value) ⇒ Object
ハンドラの呼び出し.
Instance Method Summary collapse
-
#initialize(value, parent) ⇒ SiteSettingHandler
constructor
A new instance of SiteSettingHandler.
-
#parent ⇒ Object
呼び出し元のオブジェクト.
-
#type ⇒ Object
ハンドラタイプ名 class_attribute :type, instance_writer: false.
Constructor Details
#initialize(value, parent) ⇒ SiteSettingHandler
Returns a new instance of SiteSettingHandler.
75 76 77 78 |
# File 'lib/sitesettinghandler.rb', line 75 def initialize(value, parent) @value = value @parent = parent end |
Class Attribute Details
.type ⇒ Object (readonly)
Returns the value of attribute type.
14 15 16 |
# File 'lib/sitesettinghandler.rb', line 14 def type @type end |
Class Method Details
._make_handler(parent, type, value) ⇒ Object
64 65 66 67 68 |
# File 'lib/sitesettinghandler.rb', line 64 def _make_handler(parent, type, value) # typeが未登録の場合、例外が発生する klass = @@klasses.fetch(type) klass.make(value, WeakRef.new(parent)) end |
.add_handler(path_or_type: @@current_path, klass: self) ⇒ Object
ハンドラを登録する
継承したクラスで呼び出してハンドラを登録する通常、ファイル名からタイプ名を作るが、引数で直接指定も出来るクラスを継承していない場合はクラスを指定して登録する
23 24 25 26 |
# File 'lib/sitesettinghandler.rb', line 23 def add_handler(path_or_type: @@current_path, klass: self) @type = File.basename(path_or_type, HANDLER_EXT) @@klasses[@type] = klass end |
.handler(parent, value) ⇒ Object
ハンドラの呼び出し
引数から対応するハンドラを呼び出しインスタンスを作る引数がこのクラスの派生オブジェクトならそのまま返すそれ以外でもメソッドmatchを持つならそのまま返すそれ以外なら正規表現であるので正規表現ハンドラにして返す
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sitesettinghandler.rb', line 36 def handler(parent, value) case value when Array # key: # type: value _make_handler(parent, *value) when Hash # key: # - type: value _make_handler(parent, *value.flatten) when String # key: # value /#{value}/m when self # 派生オブジェクトならそのまま返す value else if value.respond_to?(:match) # matchメソッドを持つオブジェクトならそのまま返す value else # その他であれば正規表現として生成 /#{value}/m end end end |
Instance Method Details
#parent ⇒ Object
呼び出し元のオブジェクト
87 88 89 |
# File 'lib/sitesettinghandler.rb', line 87 def parent @parent&.weakref_alive? ? @parent : nil end |
#type ⇒ Object
ハンドラタイプ名class_attribute :type, instance_writer: false
82 83 84 |
# File 'lib/sitesettinghandler.rb', line 82 def type self.class.type end |