Module: ActiveXML

Included in:
Collection, Object
Defined in:
lib/active_xml.rb,
lib/active_xml/object.rb,
lib/active_xml/version.rb,
lib/active_xml/collection.rb,
lib/active_xml/collection/query.rb,
lib/active_xml/collection/route.rb

Defined Under Namespace

Classes: Collection, Object

Constant Summary collapse

VERSION =
"0.0.4"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Instance Method Details

#delete_node(key) ⇒ Object



33
34
35
# File 'lib/active_xml.rb', line 33

def delete_node(key)
  xml.search(key).remove
end

#initialize(path) ⇒ Object



15
16
17
18
19
# 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

#saveObject



29
30
31
# File 'lib/active_xml.rb', line 29

def save
  @path.open('w') {|f| f.write(@xml.to_xml) }
end

#set_root!Object



25
26
27
# File 'lib/active_xml.rb', line 25

def set_root!
  xml.root.name = root
end

#xmlObject



21
22
23
# File 'lib/active_xml.rb', line 21

def xml
  @xml ||= Nokogiri::XML(@path.read)
end