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.



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

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.



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

def name
  @name
end

Class Method Details

.exe(name, *args) ⇒ Object



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

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

Instance Method Details

#infoObject



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

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

#pathObject



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

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

#run(*args) ⇒ Object



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

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