class Knot::Conf

Public Class Methods

new(protocol = nil) click to toggle source
# File lib/knot/interface.rb, line 86
def initialize protocol = nil
        @protocol = protocol || Protocol.new
        @transaction_opened = 0
end

Public Instance Methods

[](item, value)
Alias for: set
abort() click to toggle source
# File lib/knot/interface.rb, line 101
def abort
        @protocol.call command: 'conf-abort'
        @transaction_opened = 0
end
begin() click to toggle source
# File lib/knot/interface.rb, line 91
def begin
        @transaction_opened += 1
        @protocol.call command: 'conf-begin'   if 1 == @transaction_opened
end
commit() click to toggle source
# File lib/knot/interface.rb, line 96
def commit
        @protocol.call command: 'conf-commit'  if 1 == @transaction_opened
        @transaction_opened -= 1  if 0 < @transaction_opened
end
delete(item, value = nil)
Alias for: unset
list(item = nil) click to toggle source
# File lib/knot/interface.rb, line 152
def list item = nil
        @protocol.call (item ? parse_item( item) : {}).update( command: 'conf-list')
end
parse_item(k) click to toggle source
# File lib/knot/interface.rb, line 116
def parse_item k
        case k
        when k
                case k.keys.sort
                when %w[section], %w[id section], %w[item section], %w[id item section] then k
                else raise ArgumentError, "Invalid Item-format"
                end

        when Array
                case k.length
                when 1 then {section: k[0]}
                when 2 then {section: k[0], item: k[1]}
                when 3 then {section: k[0], id: k[1], item: k[2]}
                else raise ArgumentError, "Invalid Item-format"
                end

        when /\A
                                (?<section> [a-z0-9_-]+ )
                                (?: \[ (?<id> [a-z0-9_.-]+) \] )?
                                (?: \. (?<item>[a-z0-9_-]+) )?
                        \z/xi
                $~.named_captures.delete_if {|_,v| v.nil? }
        else raise ArgumentError, "Invalid Item-format"
        end
end
read(item = nil) click to toggle source
# File lib/knot/interface.rb, line 156
def read item = nil
        @protocol.call (item ? parse_item( item) : {}).update( command: 'conf-read')
end
set(item, value) click to toggle source
# File lib/knot/interface.rb, line 142
def set item, value
        @protocol.call parse_item( item).update( command: 'conf-set', data: value)
end
Also aliased as: []
transaction() { |self| ... } click to toggle source
# File lib/knot/interface.rb, line 106
def transaction
        self.begin
        yield self
rescue Object
        self.abort
        raise
ensure
        self.commit
end
unset(item, value = nil) click to toggle source
# File lib/knot/interface.rb, line 147
def unset item, value = nil
        @protocol.call parse_item( item).update( command: 'conf-unset', data: value)
end
Also aliased as: delete