Class: TinyTds::Bin

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

Constant Summary collapse

ROOT =
File.expand_path '../../..', __FILE__
PATHS =
ENV['PATH'].split File::PATH_SEPARATOR
EXTS =
(ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']) | ['.exe']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Bin

Returns a new instance of Bin.



23
24
25
26
27
# File 'lib/tiny_tds/bin.rb', line 23

def initialize(name)
  @name = name
  @binstub = find_bin
  @exefile = find_exe
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/tiny_tds/bin.rb', line 11

def name
  @name
end

Class Method Details

.exe(name, *args) ⇒ Object



15
16
17
18
19
# File 'lib/tiny_tds/bin.rb', line 15

def exe(name, *args)
  bin = new(name)
  puts bin.info unless args.any? { |x| x == '-q' }
  bin.run(*args)
end

Instance Method Details

#infoObject



40
41
42
# File 'lib/tiny_tds/bin.rb', line 40

def info
  "[TinyTds][v#{TinyTds::VERSION}][#{name}]: #{path}"
end

#pathObject



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

def path
  return @path if defined?(@path)
  @path = @exefile && File.exist?(@exefile) ? @exefile : which
end

#run(*args) ⇒ Object



29
30
31
32
33
# File 'lib/tiny_tds/bin.rb', line 29

def run(*args)
  return nil unless path
  Kernel.system Shellwords.join(args.unshift(path))
  $CHILD_STATUS.to_i
end