Class: Node

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Node

Returns a new instance of Node.



21
22
23
24
25
26
27
28
# File 'lib/node.rb', line 21

def initialize(file)
  @file = file
  @path = default_node_path
  @exec_name = "node"
  @node_debug = false
  @module_contexts = false
  @opts = []
end

Instance Attribute Details

#exec_nameObject

the name of the stock node.js executable, which is normally just “node”



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

def exec_name
  @exec_name
end

#module_contextsObject

If set true, loads modules in their own global contexts.



16
17
18
# File 'lib/node.rb', line 16

def module_contexts
  @module_contexts
end

#node_debugObject

If true, prints additional debug output. Defaults to false.



13
14
15
# File 'lib/node.rb', line 13

def node_debug
  @node_debug
end

#optsObject

Array of command-line arguments for node.js.



19
20
21
# File 'lib/node.rb', line 19

def opts
  @opts
end

#pathObject

the value of NODE_PATH. This is an array.



7
8
9
# File 'lib/node.rb', line 7

def path
  @path
end

Class Method Details

.path_to_gemObject

Returns the path to the node.rb gem.



42
43
44
# File 'lib/node.rb', line 42

def path_to_gem
  File.expand_path(File.join(File.dirname(__FILE__), ".."))
end

Instance Method Details

#commandObject

Constructs the execution command.



35
36
37
38
# File 'lib/node.rb', line 35

def command
  parts = [construct_path, construct_debug, construct_contexts, construct_name, construct_opts, @file]
  parts.reject { |a| a.nil? || a.length == 0 }.join " "
end

#path_to_gemObject

Returns the path to the node.rb gem.



48
49
50
# File 'lib/node.rb', line 48

def path_to_gem
  self.class.path_to_gem
end

#runObject



30
31
32
# File 'lib/node.rb', line 30

def run
  %x[#{command}].strip
end