Module: State

Extended by:
State
Included in:
State
Defined in:
lib/state.rb

Defined Under Namespace

Classes: Db

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *a, &b) ⇒ Object



203
204
205
206
# File 'lib/state.rb', line 203

def method_missing m, *a, &b
  super unless global.respond_to?(m)
  global.send(m, *a, &b)
end

Instance Method Details

#clean(name) ⇒ Object



45
46
47
48
# File 'lib/state.rb', line 45

def clean name
  fugly = %r/[^a-zA-Z0-9_-]/
  name.gsub fugly, '_'
end

#dbObject



197
198
199
# File 'lib/state.rb', line 197

def db
  Db
end

#for(*argv, &block) ⇒ Object Also known as: new



8
9
10
11
12
13
14
15
16
17
# File 'lib/state.rb', line 8

def for *argv, &block
  options = (Hash === argv.last ? argv.pop : {})
  name = argv.first 
  name ||= 'global' if(options.empty? and name.nil?)

  default_path = File.join(rootdir, clean(name)) if name
  path = getopt(:path, options, default_path)

  db.new path, options
end

#getopt(key, hash, default = nil) ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/state.rb', line 50

def getopt key, hash, default = nil
  return hash.fetch(key) if hash.has_key?(key)
  key = key.to_s
  return hash.fetch(key) if hash.has_key?(key)
  key = key.to_sym
  return hash.fetch(key) if hash.has_key?(key)
  default
end