Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

Changeset 1092

Show
Ignore:
Timestamp:
12/01/03 23:49:55 (5 years ago)
Author:
nahi
Message:

* do not split key from property if locked.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/soap/property.rb

    r1090 r1092  
    6666    if rest.empty? 
    6767      check_lock(key) 
    68       @store[key] 
     68      local_referent(key) 
    6969    else 
    7070      deref_key(key).referent(rest) 
     
    7676    if rest.empty? 
    7777      check_lock(key) 
    78       @store[key] = value 
     78      local_assign(key, value) 
    7979      local_hook(key) 
    8080    else 
     
    9898  def each_key 
    9999    @store.each do |key, value| 
    100       if value.is_a?(::SOAP::Property
     100      if propkey?(value
    101101        yield(value) 
    102102      end 
     
    107107    check_lock(key) 
    108108    ref = @store[key] ||= self.class.new 
    109     unless ref.is_a?(::SOAP::Property
     109    unless propkey?(ref
    110110      raise ArgumentError.new("key `#{key}' already defined as a value") 
    111111    end 
     
    119119  end 
    120120 
     121  def local_referent(key) 
     122    if @locked and propkey?(@store[key]) 
     123      raise TypeError.new("cannot split any key from locked property") 
     124    end 
     125    @store[key] 
     126  end 
     127 
     128  def local_assign(key, value) 
     129    if @locked and propkey?(value) 
     130      raise TypeError.new("cannot add any key to locked property") 
     131    end 
     132    @store[key] = value 
     133  end 
     134 
    121135  NO_HOOK = [].freeze 
    122136  def local_hook(key) 
    123137    @hook[key] || NO_HOOK 
     138  end 
     139 
     140  def propkey?(value) 
     141    value.is_a?(::SOAP::Property) 
    124142  end 
    125143 
  • trunk/test/soap/test_property.rb

    r1090 r1092  
    192192    assert_equal(@prop, @prop.unlock) 
    193193  end 
     194 
     195  def test_lock_split 
     196    @prop["a.b.c"] = 1 
     197    assert_instance_of(::SOAP::Property, @prop["a.b"]) 
     198    @prop["a.b.d"] = branch = ::SOAP::Property.new 
     199    @prop["a.b.d.e"] = 2 
     200    assert_equal(branch, @prop["a.b.d"]) 
     201    assert_equal(branch, @prop[:a][:b][:d]) 
     202    @prop.lock 
     203    assert_raises(TypeError) do 
     204      @prop["a.b"] 
     205    end 
     206    assert_raises(TypeError) do 
     207      @prop["a"] 
     208    end 
     209    @prop["a.b.c"] = 2 
     210    assert_equal(2, @prop["a.b.c"]) 
     211    assert_raises(TypeError) do 
     212      @prop["a.b.c"] = ::SOAP::Property.new 
     213    end 
     214  end 
    194215end 
    195216