Module: RubyXmlMapper::RubyXmlMapperClassMethods
- Defined in:
- lib/ruby-xml-mapper.rb
Instance Method Summary collapse
- #check_file(file_name) ⇒ Object
- #new_from_xml_file(file_name) ⇒ Object
- #new_from_xml_node(node) ⇒ Object
- #parse_xml_file(file_name) ⇒ Object
- #xml(args) ⇒ Object
Instance Method Details
#check_file(file_name) ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/ruby-xml-mapper.rb', line 146 def check_file file_name unless File.file?(file_name) raise "Unable to find file #{file_name.inspect}" end unless File.readable?(file_name) raise "File is not readable #{file_name.inspect}" end end |
#new_from_xml_file(file_name) ⇒ Object
156 157 158 |
# File 'lib/ruby-xml-mapper.rb', line 156 def new_from_xml_file file_name RubyXmlMapper.file_cache[file_name] ||= new_from_xml_node(parse_xml_file(file_name)) end |
#new_from_xml_node(node) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/ruby-xml-mapper.rb', line 160 def new_from_xml_node node if node.attributes["source"] unless source_dir_path raise "source_dir_path not defined in #{self.class.inspect}" end new_from_xml_file(File.(node.attributes["source"], source_dir_path)) else allocated = allocate allocated.initialize_from_xml node allocated.after_initialize if allocated.respond_to?(:after_initialize) allocated end end |
#parse_xml_file(file_name) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/ruby-xml-mapper.rb', line 131 def parse_xml_file(file_name) check_file file_name # NOTE: Don't know how to use XML::Document.file correctly. # As in libxml-ruby-1.1.3 it does not close file descriptor, so you end up with "Error: Too many open files." doc = LibXML::XML::Document.string(File.read(file_name)) # NOTE: If document does not created from file, it leads to "Segmentation fault" # doc.xinclude doc.root end |
#xml(args) ⇒ Object
174 175 176 177 178 |
# File 'lib/ruby-xml-mapper.rb', line 174 def xml args register_method = args.keys.detect {|key| self.respond_to?("register_#{key}_mapping", true)} || "self" self.__send__("register_#{register_method}_mapping", args) end |