nested 0.0.23 → 0.0.24
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.
- checksums.yaml +4 -4
- data/lib/nested.rb +12 -14
- data/nested.gemspec +1 -1
- data/test/nested_test.rb +7 -4
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 38c9a0d53765eb2f648f9d4f5ef2a9fb5fc4b528
         | 
| 4 | 
            +
              data.tar.gz: 3d8212a2d22886567404470d0b288514a961f2b5
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9e9ebefde4d1f116da2ceeaa625334d2eba6b1b54dcd45cf25e2c71f32722467b1bfbd9181f634c440704d19251cfe7fdcffd8ba4542011f48e70bde04b05698
         | 
| 7 | 
            +
              data.tar.gz: 2d7284067772373590898e15fc13cfe8df87581c39c4f446360b82199a851e32dd7a788c6f97647067d85059a732f24b328ca3a437cd8c0df49980a541158b60
         | 
    
        data/lib/nested.rb
    CHANGED
    
    | @@ -60,12 +60,7 @@ module Nested | |
| 60 60 | 
             
                  end
         | 
| 61 61 |  | 
| 62 62 | 
             
                  if member?
         | 
| 63 | 
            -
                     | 
| 64 | 
            -
                    __serialize_block = @parent.instance_variable_get("@__serialize_block")
         | 
| 65 | 
            -
             | 
| 66 | 
            -
                    serialize *__serialize_args, &__serialize_block
         | 
| 67 | 
            -
                  else
         | 
| 68 | 
            -
                    serialize &->(obj) { raise "implement serializer for #{@__resource.type} #{@__resource.name}" }
         | 
| 63 | 
            +
                    serialize *@parent.instance_variable_get("@__serialize_args")
         | 
| 69 64 | 
             
                  end
         | 
| 70 65 | 
             
                end
         | 
| 71 66 |  | 
| @@ -93,17 +88,20 @@ module Nested | |
| 93 88 | 
             
                  end
         | 
| 94 89 | 
             
                end
         | 
| 95 90 |  | 
| 96 | 
            -
                def serialize(*args | 
| 97 | 
            -
                  raise "pass either *args or &block" if args.empty? && !block && !member?
         | 
| 98 | 
            -
             | 
| 91 | 
            +
                def serialize(*args)
         | 
| 99 92 | 
             
                  @__serialize_args = args
         | 
| 100 | 
            -
                  @__serialize_block = block
         | 
| 101 93 |  | 
| 102 94 | 
             
                  @__serialize = ->(obj) do
         | 
| 103 | 
            -
                     | 
| 104 | 
            -
             | 
| 105 | 
            -
             | 
| 106 | 
            -
             | 
| 95 | 
            +
                    args.inject({}) do |memo, field|
         | 
| 96 | 
            +
                      case field
         | 
| 97 | 
            +
                        when Symbol
         | 
| 98 | 
            +
                          memo[field] = obj.is_a?(Hash) ? obj[field] : obj.send(field)
         | 
| 99 | 
            +
                        when Hash
         | 
| 100 | 
            +
                          field, proc = field.to_a.first
         | 
| 101 | 
            +
                          memo[field] = self.instance_exec(obj, &proc)
         | 
| 102 | 
            +
                      end
         | 
| 103 | 
            +
                      memo
         | 
| 104 | 
            +
                    end
         | 
| 107 105 | 
             
                  end
         | 
| 108 106 | 
             
                end
         | 
| 109 107 |  | 
    
        data/nested.gemspec
    CHANGED
    
    
    
        data/test/nested_test.rb
    CHANGED
    
    | @@ -313,12 +313,15 @@ class NestedTest < Test::Unit::TestCase | |
| 313 313 |  | 
| 314 314 | 
             
              def test_serializer
         | 
| 315 315 | 
             
                singleton!
         | 
| 316 | 
            -
                # assert_equal(@r.serializer, Nested::Resource::SERIALIZE)
         | 
| 317 316 |  | 
| 318 | 
            -
                 | 
| 319 | 
            -
             | 
| 317 | 
            +
                @r.serialize :name
         | 
| 318 | 
            +
             | 
| 319 | 
            +
                assert_equal({name: "joe"}, @r.instance_variable_get("@__serialize").call({name: "joe"}))
         | 
| 320 | 
            +
                assert_equal({name: "joe"}, @r.instance_variable_get("@__serialize").call({name: "joe", boss: true}))
         | 
| 321 | 
            +
                assert_equal({name: "joe"}, @r.instance_variable_get("@__serialize").call(OpenStruct.new({name: "joe"})))
         | 
| 320 322 |  | 
| 321 | 
            -
                 | 
| 323 | 
            +
                @r.serialize :name, virtual: ->(o){ o[:name] + "!!" }
         | 
| 324 | 
            +
                assert_equal({name: "joe", virtual: "joe!!"}, @r.instance_variable_get("@__serialize").call({name: "joe"}))
         | 
| 322 325 | 
             
              end
         | 
| 323 326 |  | 
| 324 327 | 
             
              # ----
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: nested
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.24
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Jan Zimmek
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2014-01-27 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         |