Class: Nodo::Function
- Inherits:
-
Object
- Object
- Nodo::Function
- Defined in:
- lib/nodo/function.rb
Instance Attribute Summary collapse
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#source_location ⇒ Object
readonly
Returns the value of attribute source_location.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#initialize(name, code, source_location, timeout, &block) ⇒ Function
constructor
A new instance of Function.
- #to_js ⇒ Object
Constructor Details
#initialize(name, code, source_location, timeout, &block) ⇒ Function
Returns a new instance of Function.
5 6 7 8 9 10 11 |
# File 'lib/nodo/function.rb', line 5 def initialize(name, code, source_location, timeout, &block) raise ArgumentError, 'cannot give code when block is given' if code && block code = code.strip if code raise ArgumentError, 'function code is required' if '' == code raise ArgumentError, 'code is required' unless code || block @name, @code, @source_location, @timeout = name, code || block, source_location, timeout end |
Instance Attribute Details
#code ⇒ Object (readonly)
Returns the value of attribute code.
3 4 5 |
# File 'lib/nodo/function.rb', line 3 def code @code end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/nodo/function.rb', line 3 def name @name end |
#source_location ⇒ Object (readonly)
Returns the value of attribute source_location.
3 4 5 |
# File 'lib/nodo/function.rb', line 3 def source_location @source_location end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
3 4 5 |
# File 'lib/nodo/function.rb', line 3 def timeout @timeout end |
Instance Method Details
#to_js ⇒ Object
13 14 15 16 |
# File 'lib/nodo/function.rb', line 13 def to_js js = code.respond_to?(:call) ? code.call.strip : code "const #{name} = __nodo_klass__.#{name} = (#{js});\n" end |