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 +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +15 -0
- data/CHANGELOG.md +7 -0
- data/README.md +2 -2
- data/Rakefile +2 -2
- data/lib/mongoid-archivable.rb +1 -0
- data/lib/mongoid/archivable.rb +9 -1
- data/lib/mongoid/archivable/process_localized_fields.rb +60 -0
- data/lib/mongoid/archivable/version.rb +1 -1
- data/mongoid-archivable.gemspec +1 -1
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6196888bed37db1654169604ef259efd32fcf17c
|
4
|
+
data.tar.gz: 510d60a14521bffa9a7fc0c1f128ddb2549702fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f0176ff51fca46ffbbe08af76c0f7d3feadcee54cd1d3445844bd02b21449fcd029cbab63327b196129eeb21e2078b860238e2908401657c148866ad281db43
|
7
|
+
data.tar.gz: 63262b2557d0f08feb5a138c6281f0dc416cac19fd9415b9b70413bea3044955178df39fcd227cf13dd4b86a6896d6336617e2e555f1aed4bded9900fb238d78
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2.
|
1
|
+
2.2.5
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Mongoid::Archivable
|
2
2
|
|
3
|
-
|
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
|
-
|
5
|
+
Moves Mongoid documents to an archive instead of destroying them.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
data/Rakefile
CHANGED
data/lib/mongoid-archivable.rb
CHANGED
data/lib/mongoid/archivable.rb
CHANGED
@@ -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
|
-
|
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
|
data/mongoid-archivable.gemspec
CHANGED
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.
|
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:
|
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:
|
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:
|
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:
|