Class: Rprov

Inherits:
Object
  • Object
show all
Defined in:
lib/rprov.rb,
lib/rprov/config.rb,
lib/rprov/decorator.rb

Defined Under Namespace

Classes: Config, Decorator

Constant Summary collapse

Conflict =
Class.new(StandardError)
Missing =
Class.new(StandardError)
VERSION =
"0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#memoryObject

Returns the value of attribute memory.



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

def memory
  @memory
end

#paranoidObject

Returns the value of attribute paranoid.



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

def paranoid
  @paranoid
end

Instance Method Details

#info(path) ⇒ Object



46
47
48
49
50
51
# File 'lib/rprov.rb', line 46

def info(path)
  conf = Config.new(key(path))

  puts "\nREDIS_URL:\n    #{conf.url}"
  puts "\nRun `rprov start #{path}` to start this instance"
end

#setup(path) ⇒ Object

Raises:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rprov.rb', line 28

def setup(path)
  raise Conflict if redis_conf(path)

  FileUtils.mkdir_p(path) if not File.exist?(path)

  conf = Config.generate
  conf.path     = path
  conf.memory   = memory if memory
  conf.host     = host if host
  conf.paranoid = paranoid if paranoid

  where = File.expand_path(File.join(path, "redis.%s.conf" % conf.key))

  File.open(where, "w") do |file|
    file.write conf.redis_conf
  end
end

#start(path) ⇒ Object



18
19
20
# File 'lib/rprov.rb', line 18

def start(path)
  exec("redis-server #{redis_conf!(path)}")
end

#stop(path) ⇒ Object



22
23
24
25
26
# File 'lib/rprov.rb', line 22

def stop(path)
  conf  = Config.new(key(path))
  redis = Redis.connect(:url => conf.url)
  redis.client.process(conf.shutdown_cmd)
end