Class: Iuid

Inherits:
Object
  • Object
show all
Defined in:
lib/iuid.rb,
lib/iuid/version.rb

Defined Under Namespace

Classes: VERSION

Instance Method Summary collapse

Constructor Details

#initialize(config_file = nil) ⇒ Iuid

Returns a new instance of Iuid.



5
6
7
8
9
10
11
# File 'lib/iuid.rb', line 5

def initialize(config_file=nil)
  if config_file
    @config_file = File.expand_path(config_file)
  elsif File.exists?(def_config_file=File.expand_path('~/.iuid.yaml')) || File.exists?(def_config_file=File.expand_path('/etc/iuid.yaml')) 
    @config_file = def_config_file
  end
end

Instance Method Details

#create(name, category) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/iuid.rb', line 13

def create(name,category)
  unless (uid=get(name)).nil?
    return uid
  end

  set(name,next_uid(category))
end

#delete(name) ⇒ Object



25
26
27
# File 'lib/iuid.rb', line 25

def delete(name)
  cache.delete(name)
end

#get(name) ⇒ Object



21
22
23
# File 'lib/iuid.rb', line 21

def get(name)
  cache.fetch(name)
end

#set(name, uid) ⇒ Object



29
30
31
32
33
# File 'lib/iuid.rb', line 29

def set(name,uid)
  cache[name] = uid
  cache['_all_uids'] = (alluids | [ uid ])
  uid
end