Class: Varfile::Command

Inherits:
Thor
  • Object
show all
Defined in:
lib/varfile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



7
8
9
# File 'lib/varfile.rb', line 7

def file_path
  @file_path
end

#outputObject

Returns the value of attribute output.



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

def output
  @output
end

Instance Method Details

#get(key) ⇒ Object



25
26
27
28
29
# File 'lib/varfile.rb', line 25

def get(key)
  file = file_or_default(options)
  content = read_file(file)
  puts_and_return content[key]
end

#listObject



33
34
35
36
37
# File 'lib/varfile.rb', line 33

def list
  file = file_or_default(options)
  content = read_file(file)
  puts_and_return printable_content(content)
end

#rm(key) ⇒ Object



41
42
43
44
45
46
# File 'lib/varfile.rb', line 41

def rm(key)
  file = file_or_default(options)
  content = read_file(file)
  content.delete key
  save_file(content, file)
end

#set(key, value) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/varfile.rb', line 12

def set(key, value)
  file = file_or_default(options)

  key = normalize_key(key)
  value = normalize_value(value)
 
  content = read_file(file)
  content[key] = value
  save_file(content, file)
end