Class: TinyTds::Bin

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Bin

Returns a new instance of Bin.



17
18
19
20
21
22
23
24
# File 'lib/tiny_tds/bin.rb', line 17

def initialize(name)
  @root = Gem.root_path
  @exts = (ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]) | [".exe"]

  @name = name
  @binstub = find_bin
  @exefile = find_exe
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.exe(name, *args) ⇒ Object



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

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

Instance Method Details

#infoObject



38
39
40
# File 'lib/tiny_tds/bin.rb', line 38

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

#pathObject



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

def path
  @path ||= (@exefile && File.exist?(@exefile)) ? @exefile : which
end

#run(*args) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/tiny_tds/bin.rb', line 26

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