module ActiveXML

Constants

VERSION

Attributes

path[R]

Public Class Methods

new(path) click to toggle source
# File lib/active_xml.rb, line 15
def initialize(path)
  @path = Pathname.new(path)
  create_file(@path, '<null_tag/>') unless @path.exist?
  set_root!
end

Public Instance Methods

delete_node(key) click to toggle source
# File lib/active_xml.rb, line 33
def delete_node(key)
  xml.search(key).remove
end
save() click to toggle source
# File lib/active_xml.rb, line 29
def save
  @path.open('w') {|f| f.write(@xml.to_xml) }
end
set_root!() click to toggle source
# File lib/active_xml.rb, line 25
def set_root!
  xml.root.name = root
end
xml() click to toggle source
# File lib/active_xml.rb, line 21
def xml
  @xml ||= Nokogiri::XML(@path.read)
end

Private Instance Methods

create_directory(path) click to toggle source
# File lib/active_xml.rb, line 39
def create_directory(path)
  path.descend do |pathname|
    pathname.dirname.mkdir unless pathname.dirname.exist?
  end
end
create_file(path, text) click to toggle source
# File lib/active_xml.rb, line 49
def create_file(path, text)
  create_directory(path)
  path.open('w') {|f| f.write(text)}
end
fetch_contents(source, key) click to toggle source
# File lib/active_xml.rb, line 45
def fetch_contents(source, key)
  source.css(key.to_s).map(&:content)
end