Class: Rubyang::Database::DataTree::Root
Instance Attribute Summary
Attributes inherited from Node
#children, #parent, #schema, #schema_tree
Instance Method Summary
collapse
#delete, #delete_same_choice_other_case, #edit, #edit_xpath, #find_child_schema
Methods inherited from Node
#evaluate_max_elements, #evaluate_min_elements, #evaluate_musts, #evaluate_whens, #evaluate_xpath, #evaluate_xpath_axis, #evaluate_xpath_expr, #evaluate_xpath_node_test, #evaluate_xpath_path, #evaluate_xpath_predicates, #initialize, #load_merge_xml_recursive, #root, #to_json, #to_s, #to_xml
Instance Method Details
#commit ⇒ Object
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
|
# File 'lib/rubyang/database/data_tree.rb', line 861
def commit
begin
components = self.edit( "rubyang" ).edit( "component" ).children.map{ |c|
component = c.key_values.first
hook = c.edit("hook").value
file_path = c.edit("file-path").value
[component, hook, file_path]
}
self.root.parent.component_manager.update components
self.root.parent.component_manager.run "commit"
rescue => e
@logger.debug { 'rescue in commit' }
@logger.debug { e }
ensure
backup = self.to_xml
@parent.history.push backup
end
end
|
#load_merge_json(json_str) ⇒ Object
925
926
927
928
|
# File 'lib/rubyang/database/data_tree.rb', line 925
def load_merge_json json_str
xml_str = json_to_xml( json_str )
self.load_merge_xml xml_str
end
|
#load_merge_xml(xml_str) ⇒ Object
918
919
920
|
# File 'lib/rubyang/database/data_tree.rb', line 918
def load_merge_xml xml_str
self.load_xml xml_str
end
|
#load_override_json(json_str) ⇒ Object
929
930
931
932
|
# File 'lib/rubyang/database/data_tree.rb', line 929
def load_override_json json_str
xml_str = json_to_xml( json_str )
self.load_override_xml xml_str
end
|
#load_override_xml(xml_str) ⇒ Object
921
922
923
924
|
# File 'lib/rubyang/database/data_tree.rb', line 921
def load_override_xml xml_str
@children.clear
self.load_xml xml_str
end
|
#load_xml(xml_str) ⇒ Object
914
915
916
917
|
# File 'lib/rubyang/database/data_tree.rb', line 914
def load_xml xml_str
doc_xml = REXML::Document.new( xml_str ).root
self.load_merge_xml_recursive doc_xml
end
|
#revert ⇒ Object
879
880
881
882
883
884
885
886
|
# File 'lib/rubyang/database/data_tree.rb', line 879
def revert
backup = @parent.history.pop
if backup
self.load_override_xml backup
else
self.load_override_xml self.new.to_xml
end
end
|
#to_json_recursive(_hash) ⇒ Object
901
902
903
904
905
906
907
908
909
910
911
912
913
|
# File 'lib/rubyang/database/data_tree.rb', line 901
def to_json_recursive _hash
root_tag = case @db_mode
when Rubyang::Database::DataTree::Mode::CONFIG
'config'
when Rubyang::Database::DataTree::Mode::OPER
'oper'
end
hash = Hash.new
_hash[root_tag] = hash
@children.each{ |c|
c.to_json_recursive hash
}
end
|
#to_xml_recursive(_doc, current_namespace = '') ⇒ Object
887
888
889
890
891
892
893
894
895
896
897
898
899
900
|
# File 'lib/rubyang/database/data_tree.rb', line 887
def to_xml_recursive _doc, current_namespace=''
root_tag = case @db_mode
when Rubyang::Database::DataTree::Mode::CONFIG
'config'
when Rubyang::Database::DataTree::Mode::OPER
'oper'
end
doc = _doc.add_element( root_tag )
current_namespace = @schema_tree.root.namespace
doc.add_namespace( current_namespace )
@children.each{ |c|
c.to_xml_recursive doc, current_namespace
}
end
|
#valid?(current = true) ⇒ Boolean
855
856
857
858
859
860
|
# File 'lib/rubyang/database/data_tree.rb', line 855
def valid? current=true
result = @children.inject(Rubyang::Xpath::BasicType::Boolean.new true){ |r, c|
r.and c.valid?( false )
}
result.value
end
|