Class: Keep

Inherits:
Object
  • Object
show all
Defined in:
lib/keep/disk.rb,
lib/keep.rb,
lib/keep/yaml.rb

Overview

Keep::Disk is our hook into your system. We’ll save and open files here.

Pretty cool, amirite?

Defined Under Namespace

Classes: Disk, Yaml

Constant Summary collapse

VERSION =
'0.0.3'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Keep

Initialize a new Keep instance.

path - the String file path to save configuration to

Returns nothing.



40
41
42
43
# File 'lib/keep.rb', line 40

def initialize(path)
  @path = path
  @disk = Yaml.new(path)
end

Instance Attribute Details

#diskObject

The in-memory Disk object.



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

def disk
  @disk
end

#formatObject

The configuration format outputted.



19
20
21
# File 'lib/keep.rb', line 19

def format
  @format
end

#pathObject

The path to the configuration file.



13
14
15
# File 'lib/keep.rb', line 13

def path
  @path
end

Instance Method Details

#as(format) ⇒ Object

The format of configuration output.

format - the lowercase String representation of a class inheriting Disk

Returns nothing, defaults to ‘yaml’ right now.



50
51
52
# File 'lib/keep.rb', line 50

def as(format)
  @format = 'yaml'
end

#get(key) ⇒ Object

Returns the value of the specified key.

key - a String value for the key of this Hash

Returns the value if found, otherwise nil.



69
70
71
# File 'lib/keep.rb', line 69

def get(key)
  @disk.get(key)
end

#keysObject

Accesses all of the keys we’re keeping.

Returns an Array of Objects.



83
84
85
# File 'lib/keep.rb', line 83

def keys
  @disk.keys
end

#present?(key) ⇒ Boolean

Searches for the key in the in-memory Hash.

Returns whether or not the key is present.

Returns:

  • (Boolean)


76
77
78
# File 'lib/keep.rb', line 76

def present?(key)
  @disk.present?(key)
end

#set(key, value) ⇒ Object

Sets a value to a given key.

key - a String value for the key of this Hash
value - an Object that maps to the key, will be serialized

Returns whether the save was successful.



60
61
62
# File 'lib/keep.rb', line 60

def set(key,value)
  @disk.set(key,value)
end