Class: Chanko::Function
- Inherits:
-
Object
- Object
- Chanko::Function
- Defined in:
- lib/chanko/function.rb
Constant Summary collapse
- THREAD_LOCAL_UNITS_KEY =
'Chanko::Function.units'
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Class Method Summary collapse
Instance Method Summary collapse
- #css_classes ⇒ Object
-
#initialize(unit, label, &block) ⇒ Function
constructor
A new instance of Function.
- #invoke(context, options = {}) ⇒ Object
Constructor Details
#initialize(unit, label, &block) ⇒ Function
Returns a new instance of Function.
17 18 19 20 21 |
# File 'lib/chanko/function.rb', line 17 def initialize(unit, label, &block) @unit = unit @label = label @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
3 4 5 |
# File 'lib/chanko/function.rb', line 3 def block @block end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
3 4 5 |
# File 'lib/chanko/function.rb', line 3 def label @label end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
3 4 5 |
# File 'lib/chanko/function.rb', line 3 def unit @unit end |
Class Method Details
.current_unit ⇒ Object
12 13 14 |
# File 'lib/chanko/function.rb', line 12 def current_unit units.last end |
.units ⇒ Object
8 9 10 |
# File 'lib/chanko/function.rb', line 8 def units Thread.current[THREAD_LOCAL_UNITS_KEY] ||= [] end |
Instance Method Details
#css_classes ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/chanko/function.rb', line 35 def css_classes if Config.compatible_css_class %W[ extension ext_#{unit.unit_name} ext_#{unit.unit_name}-#{label} ] else %W[ unit unit__#{unit.unit_name} unit__#{unit.unit_name}__#{label} ] end end |
#invoke(context, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/chanko/function.rb', line 23 def invoke(context, = {}) with_unit_stack(context) do with_unit_view_path(context) do capture_exception(context) do result = context.instance_eval(&block) result = decorate(result, context, [:type]) if context.view? && result.present? result end end end end |