维斯塔版本的变化_之间不适合我

发布于 2024-10-02 07:11:40 字数 1336 浏览 5 评论 0原文

我期望它是两个版本之间所有更改的并集。 (使用 Vestal 版本 1.0.2)

ruby-1.8.7-p174 > contact.version 
 => 12 
ruby-1.8.7-p174 > contact.latest_approved_version
 => 8 
ruby-1.8.7-p174 > contact.changes
 => {} 
ruby-1.8.7-p174 > contact.versions.last.changes
 => {"first_name"=>["I changed this one baby", "AdminF"]} 
ruby-1.8.7-p174 > contact.changes_between(8,12)
 => {} 
ruby-1.8.7-p174 > contact.changes_between(9,12)
 => {"deleted"=>[true, false]} 
ruby-1.8.7-p174 > contact.changes_between(10,12)
 => {} 
ruby-1.8.7-p174 > contact.changes_between(11,12)
 => {"first_name"=>["I changed this one baby", "AdminF"]} 

正如您所看到的,8 和 12 之间没有变化,但其中一些之间发生了变化。

奇怪的是我发誓这昨天还有效!

这是维斯塔正在使用的方法,我不确定问题是什么:

 def changes_between(from, to)
    from_number, to_number = versions.number_at(from), versions.number_at(to)
    return {} if from_number == to_number
    chain = versions.between(from_number, to_number).reject(&:initial?)
    return {} if chain.empty?

    backward = from_number > to_number
    backward ? chain.pop : chain.shift unless from_number == 1 || to_number == 1

    chain.inject({}) do |changes, version|
      changes.append_changes!(backward ? version.changes.reverse_changes : version.changes)
    end
  end

I was expecting it to be the union of all changes between 2 versions. (using vestal versions 1.0.2)

ruby-1.8.7-p174 > contact.version 
 => 12 
ruby-1.8.7-p174 > contact.latest_approved_version
 => 8 
ruby-1.8.7-p174 > contact.changes
 => {} 
ruby-1.8.7-p174 > contact.versions.last.changes
 => {"first_name"=>["I changed this one baby", "AdminF"]} 
ruby-1.8.7-p174 > contact.changes_between(8,12)
 => {} 
ruby-1.8.7-p174 > contact.changes_between(9,12)
 => {"deleted"=>[true, false]} 
ruby-1.8.7-p174 > contact.changes_between(10,12)
 => {} 
ruby-1.8.7-p174 > contact.changes_between(11,12)
 => {"first_name"=>["I changed this one baby", "AdminF"]} 

As you can see no changes between 8 and 12, but changes between some of them.

The weird thing is I swear this was working yesterday!

Here is the method vestal is using, im not sure what the problem is:

 def changes_between(from, to)
    from_number, to_number = versions.number_at(from), versions.number_at(to)
    return {} if from_number == to_number
    chain = versions.between(from_number, to_number).reject(&:initial?)
    return {} if chain.empty?

    backward = from_number > to_number
    backward ? chain.pop : chain.shift unless from_number == 1 || to_number == 1

    chain.inject({}) do |changes, version|
      changes.append_changes!(backward ? version.changes.reverse_changes : version.changes)
    end
  end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香橙ぽ 2024-10-09 07:11:40

您提供的示例可能没有任何问题。例如,如果版本 8 和 12 之间没有差异。即使版本 9、10 和 11 中发生了更改,如果模型的属性已恢复为相同的值,则 Changes_Between 方法将不会显示任何更改。

我认为验证这一点的最简单方法是检查:

>> contact.revert_to(8)
=> "8"
>> contact.inspect
=> "#<Contact ... >"
>> contact.revert_to(12)
=> "12"
>> contact.inspect
=> "#<Contact ... >"

然后比较输出。我想不出造成你所描述的结果的任何其他原因。

顺便说一句,您对“last_approved_version”所做的调用是您手动添加到模型中的内容还是vestal_versions 中内置的内容?因为我也使用 1.0.2lvestal_version,但我找不到任何参考。因此,如果它确实是内置的东西,那么我们可能有不同的 vestal_version 分支,这可能就是原因......

It is possible that there is nothing wrong with the example you provided. If for example there are no differences between version 8 and 12. Even though there has been changes in version 9, 10 and 11, the method changes_between will not show any changes if the model's attributes has been reverted to the same values.

I think the easiest way to verify that is to check:

>> contact.revert_to(8)
=> "8"
>> contact.inspect
=> "#<Contact ... >"
>> contact.revert_to(12)
=> "12"
>> contact.inspect
=> "#<Contact ... >"

And then compare the output. I can't think of any other reason for the result you described.

By the way, the call you made to "last_approved_version", is that something you manually added to your model or is it something built-in in vestal_versions? Because I also use the 1.0.2 vestal_version and I can't find any reference to that. So if it really is something built-in then we probably have different forks of vestal_version and that might be the cause...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文