xml_mapper 0.5.6 → 0.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/xml_mapper.rb +7 -2
- data/spec/xml_mapper_spec.rb +15 -0
- data/xml_mapper.gemspec +2 -2
- metadata +4 -4
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0.5. | 
| 1 | 
            +
            0.5.7
         | 
    
        data/lib/xml_mapper.rb
    CHANGED
    
    | @@ -4,7 +4,7 @@ require "date" | |
| 4 4 | 
             
            require "time"
         | 
| 5 5 |  | 
| 6 6 | 
             
            class XmlMapper
         | 
| 7 | 
            -
              attr_accessor :mappings, :after_map_block, :within_xpath
         | 
| 7 | 
            +
              attr_accessor :mappings, :after_map_block, :within_xpath, :selector_mode
         | 
| 8 8 |  | 
| 9 9 | 
             
              class << self
         | 
| 10 10 | 
             
                attr_accessor :mapper
         | 
| @@ -75,6 +75,10 @@ class XmlMapper | |
| 75 75 | 
             
                  @mapper ||= self.new
         | 
| 76 76 | 
             
                end
         | 
| 77 77 |  | 
| 78 | 
            +
                def selector_mode(style)
         | 
| 79 | 
            +
                  self.mapper.selector_mode = style
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
             | 
| 78 82 | 
             
                def include_mapper(clazz)
         | 
| 79 83 | 
             
                  self.mapper.mappings += clazz.mapper.mappings
         | 
| 80 84 | 
             
                end
         | 
| @@ -82,6 +86,7 @@ class XmlMapper | |
| 82 86 |  | 
| 83 87 | 
             
              def initialize
         | 
| 84 88 | 
             
                self.mappings = []
         | 
| 89 | 
            +
                self.selector_mode = :search
         | 
| 85 90 | 
             
              end
         | 
| 86 91 |  | 
| 87 92 | 
             
              def extract_options_from_args(args)
         | 
| @@ -155,7 +160,7 @@ class XmlMapper | |
| 155 160 |  | 
| 156 161 | 
             
              def value_from_doc_and_mapping(doc, mapping, xml_path = nil)
         | 
| 157 162 | 
             
                if mapping[:type] == :many
         | 
| 158 | 
            -
                  mapping[:options][:mapper].attributes_from_xml(doc. | 
| 163 | 
            +
                  mapping[:options][:mapper].attributes_from_xml(doc.send(self.selector_mode, mapping[:xpath]).to_a, xml_path)
         | 
| 159 164 | 
             
                else
         | 
| 160 165 | 
             
                  node = mapping[:xpath].length == 0 ? doc : doc.xpath(mapping[:xpath]).first
         | 
| 161 166 | 
             
                  if mapping[:type] == :exists
         | 
    
        data/spec/xml_mapper_spec.rb
    CHANGED
    
    | @@ -873,4 +873,19 @@ describe "XmlMapper" do | |
| 873 873 |  | 
| 874 874 | 
             
                Mapper.attributes_from_xml(xml).should == { :title => "Black on Both Sides" }
         | 
| 875 875 | 
             
              end
         | 
| 876 | 
            +
              
         | 
| 877 | 
            +
              it "allows forcing xpath style selectors" do
         | 
| 878 | 
            +
                mapper = create_class.new
         | 
| 879 | 
            +
                mapper.add_mapping(:many, { "tracks/track" => :tracks }, :mapper => XmlMapper.new)
         | 
| 880 | 
            +
                mapper.selector_mode = :xpath
         | 
| 881 | 
            +
                node = mock("nokogiri node")
         | 
| 882 | 
            +
                node.should_receive(:send).with(:xpath, "tracks/track")
         | 
| 883 | 
            +
                Nokogiri.stub(:XML).and_return {node}
         | 
| 884 | 
            +
                xml = %(
         | 
| 885 | 
            +
                      <album>
         | 
| 886 | 
            +
                        <title>Black on Both Sides</title>
         | 
| 887 | 
            +
                      </album>
         | 
| 888 | 
            +
                )
         | 
| 889 | 
            +
                mapper.attributes_from_xml(xml)
         | 
| 890 | 
            +
              end
         | 
| 876 891 | 
             
            end
         | 
    
        data/xml_mapper.gemspec
    CHANGED
    
    | @@ -5,11 +5,11 @@ | |
| 5 5 |  | 
| 6 6 | 
             
            Gem::Specification.new do |s|
         | 
| 7 7 | 
             
              s.name = %q{xml_mapper}
         | 
| 8 | 
            -
              s.version = "0.5. | 
| 8 | 
            +
              s.version = "0.5.7"
         | 
| 9 9 |  | 
| 10 10 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
         | 
| 11 11 | 
             
              s.authors = ["Tobias Schwab"]
         | 
| 12 | 
            -
              s.date = %q{2011- | 
| 12 | 
            +
              s.date = %q{2011-08-02}
         | 
| 13 13 | 
             
              s.description = %q{Declarative XML to Ruby mapping}
         | 
| 14 14 | 
             
              s.email = %q{tobias.schwab@dynport.de}
         | 
| 15 15 | 
             
              s.extra_rdoc_files = [
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: xml_mapper
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 5
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 8 | 
             
              - 5
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 0.5. | 
| 9 | 
            +
              - 7
         | 
| 10 | 
            +
              version: 0.5.7
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Tobias Schwab
         | 
| @@ -15,7 +15,7 @@ autorequire: | |
| 15 15 | 
             
            bindir: bin
         | 
| 16 16 | 
             
            cert_chain: []
         | 
| 17 17 |  | 
| 18 | 
            -
            date: 2011- | 
| 18 | 
            +
            date: 2011-08-02 00:00:00 Z
         | 
| 19 19 | 
             
            dependencies: 
         | 
| 20 20 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 21 21 | 
             
              requirement: &id001 !ruby/object:Gem::Requirement 
         |