Module: Beagle

Defined in:
lib/darkext/beagle.rb

Defined Under Namespace

Classes: BeagleError, BeagleResultsHelper

Class Method Summary collapse

Class Method Details

.homeObject



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

def self.home
  ENV['BEAGLE_HOME']
end

.home=(home) ⇒ Object



52
53
54
# File 'lib/darkext/beagle.rb', line 52

def self.home=(home)
  ENV['BEAGLE_HOME'] = home
end

.query(query, max_hits = 100) ⇒ Object

Raises:



66
67
68
69
70
71
72
73
74
75
# File 'lib/darkext/beagle.rb', line 66

def self.query(query, max_hits = 100)
  raise BeagleError, "Beagle.home (BEAGLE_HOME) not set!" if home.nil?
  args = Array.new
  args << 'beagle-query'
  args << '--verbose'
  args << '--max-hits'
  args << max_hits.to_s
  args << "\"#{query.gsub('"','\"')}\""
  return BeagleResultsHelper.new(IO.popen(args.join(' ')))
end

.running?Boolean

Returns:

  • (Boolean)

Raises:



77
78
79
80
81
82
# File 'lib/darkext/beagle.rb', line 77

def self.running?
  raise BeagleError, "Beagle.home (BEAGLE_HOME) not set!" if home.nil?
  s = status
  return false if s.include?("Could not connect") || s.empty?
  return true
end

.startObject

Raises:



56
57
58
59
# File 'lib/darkext/beagle.rb', line 56

def self.start
  raise BeagleError, "Beagle.home (BEAGLE_HOME) not set!" if home.nil?
  system('beagled --backend Files')
end

.statusObject

Raises:



84
85
86
87
# File 'lib/darkext/beagle.rb', line 84

def self.status
  raise BeagleError, "Beagle.home (BEAGLE_HOME) not set!" if home.nil?
  DarkIO.capture_output(:stderr => false) { system('beagle-info','--status') }.strip
end

.stopObject

Raises:



61
62
63
64
# File 'lib/darkext/beagle.rb', line 61

def self.stop
  raise BeagleError, "Beagle.home (BEAGLE_HOME) not set!" if home.nil?
  system('beagle-shutdown')
end