Class: Synvert::Core::Helper
- Inherits:
-
Object
- Object
- Synvert::Core::Helper
- Defined in:
- lib/synvert/core/helper.rb
Overview
Helper is used to define shared snippet.
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.availables ⇒ Hash<String, Synvert::Core::Helper>
Get all available helpers.
-
.clear ⇒ Object
Clear all registered helpers.
-
.fetch(name) ⇒ Synvert::Core::Helper
Fetch a helper by name.
-
.register(name, helper) ⇒ Object
Register a helper with its name.
Instance Method Summary collapse
-
#initialize(name) { ... } ⇒ Helper
constructor
Initialize a Helper.
Constructor Details
#initialize(name) { ... } ⇒ Helper
Initialize a Helper. When a helper is initialized, it is already registered.
51 52 53 54 55 |
# File 'lib/synvert/core/helper.rb', line 51 def initialize(name, &block) @name = name @block = block self.class.register(name, self) end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
6 7 8 |
# File 'lib/synvert/core/helper.rb', line 6 def block @block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/synvert/core/helper.rb', line 6 def name @name end |
Class Method Details
.availables ⇒ Hash<String, Synvert::Core::Helper>
Get all available helpers
30 31 32 |
# File 'lib/synvert/core/helper.rb', line 30 def availables helpers end |
.clear ⇒ Object
Clear all registered helpers.
35 36 37 |
# File 'lib/synvert/core/helper.rb', line 35 def clear helpers.clear end |
.fetch(name) ⇒ Synvert::Core::Helper
Fetch a helper by name.
22 23 24 25 |
# File 'lib/synvert/core/helper.rb', line 22 def fetch(name) name = name.to_s helpers[name] end |
.register(name, helper) ⇒ Object
Register a helper with its name.
13 14 15 16 |
# File 'lib/synvert/core/helper.rb', line 13 def register(name, helper) name = name.to_s helpers[name] = helper end |