mongoid-archivable 1.5.0 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d281f023d49fddd082a7afd6c8287c653fb9db96
4
- data.tar.gz: 0a289215bf188f0596ede2dfa32d1693d04ebc02
3
+ metadata.gz: 6196888bed37db1654169604ef259efd32fcf17c
4
+ data.tar.gz: 510d60a14521bffa9a7fc0c1f128ddb2549702fa
5
5
  SHA512:
6
- metadata.gz: 7accbb6a07ee5027898e8d1834cc2ca08360cbb5ac6f9a4ec8c73248a4b9551e8cbf83b5744d588db9190d6818e535702ef4138fc45a7a4e1fdfed232a7cf73c
7
- data.tar.gz: d16615059c613e8dab9c63495e8bd84ebd95ccf3acf87950b95b7dce1c193271655026edb2523daad4b1f67482ea4b99528584a2ac308fc8a2e27769e0b5826e
6
+ metadata.gz: 1f0176ff51fca46ffbbe08af76c0f7d3feadcee54cd1d3445844bd02b21449fcd029cbab63327b196129eeb21e2078b860238e2908401657c148866ad281db43
7
+ data.tar.gz: 63262b2557d0f08feb5a138c6281f0dc416cac19fd9415b9b70413bea3044955178df39fcd227cf13dd4b86a6896d6336617e2e555f1aed4bded9900fb238d78
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.2
1
+ 2.2.5
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ script: 'bundle exec rake'
3
+ sudo: false
4
+ rvm:
5
+ - 2.2.5
6
+ services:
7
+ - mongodb
8
+
9
+ notifications:
10
+ email:
11
+ recipients:
12
+ - joost@spacebabies.nl
13
+ - tomas.celizna@gmail.com
14
+ on_failure: change
15
+ on_success: never
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # 1.5.2
2
+
3
+ * correctly restore localized fields on self and embedded documents
4
+
5
+ # 1.5.0
6
+
7
+ * support Mongoid 6
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # Mongoid::Archivable
2
2
 
3
- Moves Mongoid documents to an archive instead of destroying them.
3
+ [![Build Status](https://travis-ci.org/Sign2Pay/mongoid-archivable.svg)](https://travis-ci.org/Sign2Pay/mongoid-archivable) [![Gem Version](https://badge.fury.io/rb/mongoid-archivable.svg)](http://badge.fury.io/rb/mongoid-archivable)
4
4
 
5
- [ ![Codeship Status for Sign2Pay/mongoid-archivable](https://codeship.com/projects/a6d39180-c4c7-0132-bf85-1a3509ce6b71/status?branch=master)](https://codeship.com/projects/74192)
5
+ Moves Mongoid documents to an archive instead of destroying them.
6
6
 
7
7
  ## Installation
8
8
 
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new
5
5
 
@@ -1,2 +1,3 @@
1
1
  require 'mongoid/archivable/version'
2
+ require 'mongoid/archivable/process_localized_fields'
2
3
  require 'mongoid/archivable'
@@ -1,4 +1,5 @@
1
1
  require 'active_support/concern'
2
+ require 'mongoid/archivable/process_localized_fields'
2
3
 
3
4
  module Mongoid
4
5
  module Archivable
@@ -14,7 +15,10 @@ module Mongoid
14
15
  def original_document
15
16
  @original_document ||= begin
16
17
  excluded_attributes = %w(_id original_id original_type archived_at)
17
- original_class_name.constantize.new(attributes.except(*excluded_attributes)) do |doc|
18
+ attrs = attributes.except(*excluded_attributes)
19
+ attrs = Mongoid::Archivable::ProcessLocalizedFields.call(original_class, attrs)
20
+
21
+ original_class.new(attrs) do |doc|
18
22
  doc.id = original_id
19
23
  end
20
24
  end
@@ -30,6 +34,10 @@ module Mongoid
30
34
  self.class.to_s.gsub(/::Archive\z/, '') # gem version < 1.3.0, turns "User::Archive" into "User".
31
35
  end
32
36
  end
37
+
38
+ def original_class
39
+ original_class_name.constantize
40
+ end
33
41
  end
34
42
 
35
43
  included do
@@ -0,0 +1,60 @@
1
+ module Mongoid
2
+ module Archivable
3
+ # loops through all fields on document, as well as on its embedded relations
4
+ # and makes sure all attributes that belong to localized fields are assigned
5
+ # via their *_translations writer
6
+ class ProcessLocalizedFields < Struct.new(:cls, :attrs)
7
+ def self.call(*args)
8
+ new(*args).call
9
+ end
10
+
11
+ def initialize(cls, attrs = {})
12
+ super(cls, attrs)
13
+ end
14
+
15
+ def call
16
+ attrs = convert_fields
17
+
18
+ embedded_relations.each do |relation|
19
+ relation_name = relation.name.to_s
20
+ relation_class = relation.class_name.constantize
21
+
22
+ # convert embeds_many
23
+ if attrs[relation_name].is_a?(Array)
24
+ attrs[relation_name] = attrs[relation_name].map do |att|
25
+ ProcessLocalizedFields.call(relation_class, att)
26
+ end
27
+ # convert embeds_one
28
+ elsif att = attrs[relation_name]
29
+ attrs[relation_name] = ProcessLocalizedFields.call(relation_class, att)
30
+ end
31
+ end
32
+
33
+ attrs
34
+ end
35
+
36
+ private
37
+
38
+ def localized_fields
39
+ cls.fields.values.select(&:localized?)
40
+ end
41
+
42
+ def localized_field_names
43
+ localized_fields.map(&:name)
44
+ end
45
+
46
+ def convert_fields
47
+ attrs.map do |name, value|
48
+ if localized_field_names.include?(name.to_s)
49
+ name = "#{name}_translations"
50
+ end
51
+ [name, value]
52
+ end.to_h
53
+ end
54
+
55
+ def embedded_relations
56
+ cls.relations.values.select(&:embedded?)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Archivable
3
- VERSION = '1.5.0'.freeze
3
+ VERSION = '1.5.2'.freeze
4
4
  end
5
5
  end
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency 'bundler'
26
26
  spec.add_development_dependency 'rake'
27
- spec.add_development_dependency 'rspec', '~> 3.2.0'
27
+ spec.add_development_dependency 'rspec'
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-archivable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joost Baaij
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-13 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 3.2.0
75
+ version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 3.2.0
82
+ version: '0'
83
83
  description: Move Mongoid documents to an archive instead of destroying them.
84
84
  email:
85
85
  - joost@spacebabies.nl
@@ -90,6 +90,8 @@ files:
90
90
  - ".gitignore"
91
91
  - ".rspec"
92
92
  - ".ruby-version"
93
+ - ".travis.yml"
94
+ - CHANGELOG.md
93
95
  - CODE_OF_CONDUCT.md
94
96
  - Gemfile
95
97
  - LICENSE.txt
@@ -99,6 +101,7 @@ files:
99
101
  - bin/setup
100
102
  - lib/mongoid-archivable.rb
101
103
  - lib/mongoid/archivable.rb
104
+ - lib/mongoid/archivable/process_localized_fields.rb
102
105
  - lib/mongoid/archivable/version.rb
103
106
  - mongoid-archivable.gemspec
104
107
  homepage: https://github.com/Sign2Pay/mongoid-archivable
@@ -121,9 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
124
  version: '0'
122
125
  requirements: []
123
126
  rubyforge_project:
124
- rubygems_version: 2.4.5
127
+ rubygems_version: 2.4.5.1
125
128
  signing_key:
126
129
  specification_version: 4
127
130
  summary: Move Mongoid documents to an archive instead of destroying them.
128
131
  test_files: []
129
- has_rdoc: