Class: Synvert::Core::Helper

Inherits:
Object
  • Object
show all
Defined in:
lib/synvert/core/helper.rb

Overview

Helper is used to define shared snippet.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) { ... } ⇒ Helper

Initialize a Helper. When a helper is initialized, it is already registered.

Parameters:

  • name (String)

    name of the helper.

Yields:

  • defines the behaviors of the helper, block code won't be called when initialization.



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

#blockObject (readonly)

Returns the value of attribute block.



6
7
8
# File 'lib/synvert/core/helper.rb', line 6

def block
  @block
end

#nameObject (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

.availablesHash<String, Synvert::Core::Helper>

Get all available helpers

Returns:



30
31
32
# File 'lib/synvert/core/helper.rb', line 30

def availables
  helpers
end

.clearObject

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.

Parameters:

  • name (String)

    rewrtier name.

Returns:



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.

Parameters:



13
14
15
16
# File 'lib/synvert/core/helper.rb', line 13

def register(name, helper)
  name = name.to_s
  helpers[name] = helper
end