kakurenbo-puti 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kakurenbo_puti/active_record_base.rb +42 -18
- data/lib/kakurenbo_puti/version.rb +1 -1
- 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: 4a224bebe0029c5a6c736176831dd549df38df0a
|
4
|
+
data.tar.gz: 6bac0bc291bd5318c582a18f435b63850bcc598d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8d590bfc647fbe0a63d2d743e354bed23480f89c4326def4f9c5663ccd56e9e973a8043841971360426d9b996fbb0ecbd832d78578fe9b0f03f58c4a2cceb0a
|
7
|
+
data.tar.gz: 32cac6cab3b8035e9983c53685809ea30c5eaec0ab2a26240c913cb76d21d8f4c50304f86d44acebe86ac6b2cb6bcd9f4f7dad1c10771fd25901617287c19473
|
@@ -4,30 +4,54 @@ module KakurenboPuti
|
|
4
4
|
# Enable soft-delete.
|
5
5
|
# @raise [StandardException] if Not found soft-deleted date column.
|
6
6
|
#
|
7
|
-
# @param [Symbol] column
|
8
|
-
# @param [Array<Symbol>] dependent_associations
|
7
|
+
# @param [Symbol] column Name of soft-deleted date column.
|
8
|
+
# @param [Array<Symbol>] dependent_associations Names of dependency association.
|
9
9
|
def soft_deletable(column: :soft_destroyed_at, dependent_associations: [])
|
10
|
-
|
10
|
+
Initializers.create_callbacks self
|
11
|
+
Initializers.create_column_name_accessors self, column
|
12
|
+
Initializers.create_scopes self, dependent_associations
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
include InstanceMethods
|
15
|
+
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
+
module Initializers
|
18
|
+
# Create callbacks.
|
19
|
+
# @param [Class] target_class Class of target.
|
20
|
+
def self.create_callbacks(target_class)
|
21
|
+
target_class.class_eval do
|
22
|
+
define_model_callbacks :restore
|
23
|
+
define_model_callbacks :soft_destroy
|
24
|
+
end
|
25
|
+
end
|
17
26
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
relation.joins(name).references(name)
|
26
|
-
end
|
27
|
+
# Create attribute_accessors of column_name.
|
28
|
+
# @param [Class] target_class Class of target.
|
29
|
+
# @param [Symbol] column Name of column.
|
30
|
+
def self.create_column_name_accessors(target_class, column)
|
31
|
+
target_class.class_eval do
|
32
|
+
define_singleton_method(:soft_delete_column) { column }
|
33
|
+
delegate :soft_delete_column, to: :class
|
27
34
|
end
|
28
|
-
end
|
35
|
+
end
|
29
36
|
|
30
|
-
|
37
|
+
# Create scopes.
|
38
|
+
# @param [Class] target_class Class of target.
|
39
|
+
# @param [Array<Symbol>] dependent_associations Names of dependency association.
|
40
|
+
def self.create_scopes(target_class, dependent_associations)
|
41
|
+
target_class.class_eval do
|
42
|
+
scope :only_soft_destroyed, -> { where.not(id: without_soft_destroyed.select(:id)) }
|
43
|
+
scope :without_soft_destroyed, (lambda do
|
44
|
+
dependent_associations.inject(where(soft_delete_column => nil)) do |relation, name|
|
45
|
+
association = relation.klass.reflect_on_all_associations.find{|a| a.name == name }
|
46
|
+
if association.klass.method_defined?(:soft_delete_column)
|
47
|
+
relation.joins(name).merge(association.klass.without_soft_destroyed).references(name)
|
48
|
+
else
|
49
|
+
relation.joins(name).references(name)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end)
|
53
|
+
end
|
54
|
+
end
|
31
55
|
end
|
32
56
|
|
33
57
|
module InstanceMethods
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kakurenbo-puti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alfa-jpn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|