Class: Nyanko::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/nyanko/function.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#blockObject (readonly)

Returns the value of attribute block.



3
4
5
# File 'lib/nyanko/function.rb', line 3

def block
  @block
end

#labelObject (readonly)

Returns the value of attribute label.



3
4
5
# File 'lib/nyanko/function.rb', line 3

def label
  @label
end

#unitObject (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_unitObject



10
11
12
# File 'lib/nyanko/function.rb', line 10

def current_unit
  units.last
end

.unitsObject



6
7
8
# File 'lib/nyanko/function.rb', line 6

def units
  @units ||= []
end

Instance Method Details

#css_classesObject



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, options = {})
  with_unit_stack(context) do
    with_unit_view_path(context) do
      capture_exception(context) do
        result = context.instance_eval(&block)
        result = decorate(result, context, options[:type]) if context.view? && result.present?
        result
      end
    end
  end
end