Class: Nyanko::Function
- Inherits:
-
Object
- Object
- Nyanko::Function
- Defined in:
- lib/nyanko/function.rb
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.
15 16 17 18 19 |
# File 'lib/nyanko/function.rb', line 15 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/nyanko/function.rb', line 3 def block @block end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
3 4 5 |
# File 'lib/nyanko/function.rb', line 3 def label @label end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
3 4 5 |
# File 'lib/nyanko/function.rb', line 3 def unit @unit end |
Class Method Details
.current_unit ⇒ Object
10 11 12 |
# File 'lib/nyanko/function.rb', line 10 def current_unit units.last end |
.units ⇒ Object
6 7 8 |
# File 'lib/nyanko/function.rb', line 6 def units @units ||= [] end |
Instance Method Details
#css_classes ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/nyanko/function.rb', line 33 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
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/nyanko/function.rb', line 21 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 |