Class: Bogy
- Inherits:
-
Object
show all
- Defined in:
- lib/bogy.rb,
lib/bogy/handler.rb,
lib/bogy/version.rb,
lib/bogy/writeable.rb,
lib/bogy/file_handler.rb,
lib/bogy/hash_handler.rb,
lib/bogy/string_handler.rb
Defined Under Namespace
Modules: Writeable
Classes: FileHandler, Handler, HashHandler, StringHandler
Constant Summary
collapse
- VERSION =
'1.1'.freeze
Instance Method Summary
collapse
Constructor Details
#initialize(options = nil) ⇒ Bogy
Returns a new instance of Bogy.
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/bogy.rb', line 10
def initialize(options = nil)
fail ArgumentError, 'wrong number of arguments (0 for 1)' if options.nil?
fail ArgumentError, 'you should provide only one argument' if options.length > 1
@handler =
if options[:file]
FileHandler.new(options[:file])
elsif options[:hash]
HashHandler.new(options[:hash])
elsif options[:string]
StringHandler.new(options[:string])
end
end
|
Instance Method Details
#[](key) ⇒ Object
27
28
29
|
# File 'lib/bogy.rb', line 27
def [](key)
@handler.hash[key]
end
|
#[]=(key, value) ⇒ Object
31
32
33
34
|
# File 'lib/bogy.rb', line 31
def []=(key, value)
@handler.hash[key] = value
@handler.write if @handler.is_a? Writeable
end
|
#delete(key) ⇒ Object
36
37
38
39
40
|
# File 'lib/bogy.rb', line 36
def delete(key)
deleted = @handler.hash.delete(key)
@handler.write if @handler.is_a? Writeable
deleted
end
|
#to_h ⇒ Object
42
43
44
|
# File 'lib/bogy.rb', line 42
def to_h
@handler.hash
end
|
#to_yaml ⇒ Object
46
47
48
|
# File 'lib/bogy.rb', line 46
def to_yaml
@handler.hash.to_yaml
end
|
#write_to_file(path) ⇒ Object
50
51
52
|
# File 'lib/bogy.rb', line 50
def write_to_file(path)
IO.write(path, @handler.hash.to_yaml)
end
|