card-mod-mirror 0.1 → 0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/set/abstract/reflection.rb +72 -0
- data/set/all/list_changes.rb +8 -42
- data/set/type/mirror_list.rb +3 -91
- data/set/type/mirrored_list.rb +3 -108
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a03627c98bc1228609133d186a4c4e12b8b0d9353afb856f3a4169d640437dd
|
4
|
+
data.tar.gz: b037feb0fbecef3d2ec8088298edfacde1b6d9e5ec9b052dd613a882a33361b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b26a2ca35ace3fd3b34fc91342690b9d9020d96269c3224a535c592779836e03eb47f0c2d19c39caa5fb649fd134a62db2eab9e935487eb0bce7d2b9a7522ee2
|
7
|
+
data.tar.gz: 49722cac50ab8fef88ef5a1a74f720d5369fd17eea36f1a2b99d845aacfe9f4bc2ecaff7679fc4ca5c50efe554b94c3cfb027d9b67e408971c0ca993cfbccc7d
|
@@ -0,0 +1,72 @@
|
|
1
|
+
include_set Abstract::Pointer
|
2
|
+
|
3
|
+
event :validate_mirrorable, :validate, on: :save, changed: :name do
|
4
|
+
return if right&.type_code == :cardtype
|
5
|
+
|
6
|
+
errors.add :name, t(:mirror_cardtype_right)
|
7
|
+
end
|
8
|
+
|
9
|
+
event :validate_mirror_items, :validate, on: :save do
|
10
|
+
item_cards.each do |item_card|
|
11
|
+
next if item_card.type_id == item_type_id
|
12
|
+
|
13
|
+
errors.add :content, t(:mirror_only_type_allowed,
|
14
|
+
cardname: item_card.name,
|
15
|
+
cardtype: item_type_name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
event :update_mirroring_card, :prepare_to_validate,
|
20
|
+
changed: :content, skip: :allowed do
|
21
|
+
remove_mirrored_items dropped_item_names
|
22
|
+
add_mirrored_items added_item_names
|
23
|
+
end
|
24
|
+
|
25
|
+
def remove_mirrored_items items
|
26
|
+
each_mirrored_subcard(items) { |sc| sc.drop_item name.left }
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_mirrored_items items
|
30
|
+
each_mirrored_subcard(items) { |sc| sc.add_item name.left }
|
31
|
+
end
|
32
|
+
|
33
|
+
def each_mirrored_subcard items
|
34
|
+
items.each do |item|
|
35
|
+
sc = subcard mirrored_card(item)
|
36
|
+
sc.skip_event! :update_mirroring_card
|
37
|
+
yield sc
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def mirrored_card item
|
42
|
+
Card.fetch [item, left.type_name], new: { type: mirroring_type }
|
43
|
+
end
|
44
|
+
|
45
|
+
def generate_content
|
46
|
+
listed_by.map { |item| item.to_name.left }.join "\n"
|
47
|
+
end
|
48
|
+
|
49
|
+
def listed_by
|
50
|
+
Card.search({ type: :mirrored_list,
|
51
|
+
right: trunk.type_name,
|
52
|
+
left: { type_id: item_type_id },
|
53
|
+
refer_to: name.trunk,
|
54
|
+
return: :name }, "all cards listed by #{name}")
|
55
|
+
end
|
56
|
+
|
57
|
+
def item_type
|
58
|
+
name.right
|
59
|
+
end
|
60
|
+
|
61
|
+
def item_type_name
|
62
|
+
name.right_name
|
63
|
+
end
|
64
|
+
|
65
|
+
def item_type_card
|
66
|
+
name.right
|
67
|
+
end
|
68
|
+
|
69
|
+
def item_type_id
|
70
|
+
right_id
|
71
|
+
end
|
72
|
+
|
data/set/all/list_changes.rb
CHANGED
@@ -1,49 +1,15 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
event :preserve_mirrors, :validate,
|
4
|
+
on: :update, changed: :type_id, when: :item_in_mirror? do
|
5
|
+
errors.add :type, "cannot change type of item in mirrors: #{items_in_mirrors.join ', '}"
|
5
6
|
end
|
6
7
|
|
7
|
-
def
|
8
|
-
|
8
|
+
def items_in_mirrors
|
9
|
+
@items_in_mirrors ||=
|
10
|
+
Card.search left: name, type_id: [MirrorListID, MirroredListID], return: :name
|
9
11
|
end
|
10
12
|
|
11
|
-
def
|
12
|
-
|
13
|
-
"lists that link to #{name}")
|
14
|
-
end
|
15
|
-
|
16
|
-
def codename_list_exist?
|
17
|
-
Card::Codename.exist?(:mirrored_list) && Card::Codename.exist?(:mirror_list)
|
18
|
-
end
|
19
|
-
|
20
|
-
event :trunk_cardtype_of_a_list_relation_changed, :finalize,
|
21
|
-
changed: :type, on: :update, when: :codename_list_exist? do
|
22
|
-
type_key_was = Card.quick_fetch(type_id_before_act)&.key
|
23
|
-
|
24
|
-
list_fields.each do |card|
|
25
|
-
card.update_listed_by_cache_for card.item_keys, type_key: type_key_was
|
26
|
-
card.update_listed_by_cache_for card.item_keys
|
27
|
-
end
|
28
|
-
listed_by_fields.each &:update_cached_list
|
29
|
-
end
|
30
|
-
|
31
|
-
event :trunk_name_of_a_list_relation_changed, :finalize,
|
32
|
-
changed: :name, on: :update,
|
33
|
-
when: :codename_list_exist? do
|
34
|
-
list_fields.each do |card|
|
35
|
-
card.update_listed_by_cache_for card.item_keys
|
36
|
-
end
|
37
|
-
listed_by_fields.each &:update_cached_list
|
38
|
-
end
|
39
|
-
|
40
|
-
event :cardtype_of_list_item_changed, :validate,
|
41
|
-
changed: :type, on: :save,
|
42
|
-
when: :codename_list_exist? do
|
43
|
-
linker_lists.each do |card|
|
44
|
-
next unless card.item_type_id != type_id
|
45
|
-
errors.add(:type,
|
46
|
-
"can't be changed because #{name} " \
|
47
|
-
"is referenced by list card #{card.name}")
|
48
|
-
end
|
13
|
+
def item_in_mirror?
|
14
|
+
items_in_mirrors.present?
|
49
15
|
end
|
data/set/type/mirror_list.rb
CHANGED
@@ -1,93 +1,5 @@
|
|
1
|
-
include_set Abstract::
|
1
|
+
include_set Abstract::Reflection
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
errors.add :name, t(:mirror_cardtype_right)
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
event :validate_listed_by_content, :validate,
|
10
|
-
on: :save, changing: :content do
|
11
|
-
item_cards(content: content).each do |item_card|
|
12
|
-
next unless item_card.type_id != right.id
|
13
|
-
errors.add(
|
14
|
-
:content,
|
15
|
-
"#{item_card.name} has wrong cardtype; " \
|
16
|
-
"only cards of type #{name.right} are allowed"
|
17
|
-
)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
event :update_content_in_list_cards, :prepare_to_validate,
|
22
|
-
on: :save, changing: :content do
|
23
|
-
return unless db_content.present?
|
24
|
-
new_items = item_keys(content: db_content)
|
25
|
-
old_items = item_keys(content: old_content)
|
26
|
-
remove_items(old_items - new_items)
|
27
|
-
add_items(new_items - old_items)
|
28
|
-
end
|
29
|
-
|
30
|
-
def old_content
|
31
|
-
db_content_before_act.present? ? db_content_before_act : content_cache.read(key)
|
32
|
-
end
|
33
|
-
|
34
|
-
def remove_items items
|
35
|
-
items.each do |item|
|
36
|
-
next unless (lc = list_card item)
|
37
|
-
lc.drop_item name.left
|
38
|
-
subcards.add lc
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def add_items items
|
43
|
-
items.each do |item|
|
44
|
-
if (lc = list_card(item))
|
45
|
-
lc.add_item name.left
|
46
|
-
subcards.add lc
|
47
|
-
else
|
48
|
-
subcards.add(name: [item, left.type_name].cardname,
|
49
|
-
type: "list",
|
50
|
-
content: "[[#{name.left}]]")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def content_cache
|
56
|
-
Card::Cache[Card::Set::Type::MirrorList]
|
57
|
-
end
|
58
|
-
|
59
|
-
def content
|
60
|
-
content_cache.fetch(key) do
|
61
|
-
generate_content
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def generate_content
|
66
|
-
listed_by.map do |item|
|
67
|
-
"[[%s]]" % item.to_name.left
|
68
|
-
end.join "\n"
|
69
|
-
end
|
70
|
-
|
71
|
-
def listed_by
|
72
|
-
Card.search(
|
73
|
-
{ type_id: Card::MirroredListID, right: trunk.type_name,
|
74
|
-
left: { type: name.tag }, refer_to: name.trunk, return: :name },
|
75
|
-
"all cards listed by #{name}"
|
76
|
-
)
|
77
|
-
end
|
78
|
-
|
79
|
-
def update_cached_list
|
80
|
-
if trunk
|
81
|
-
Card::Cache[Card::Set::Type::MirrorList].write key, generate_content
|
82
|
-
else
|
83
|
-
Card::Cache[Card::Set::Type::MirrorList].delete key
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def list_card item
|
88
|
-
Card.fetch item, left.type_name
|
89
|
-
end
|
90
|
-
|
91
|
-
def unfilled?
|
92
|
-
false
|
3
|
+
def mirroring_type
|
4
|
+
:mirrored_list
|
93
5
|
end
|
data/set/type/mirrored_list.rb
CHANGED
@@ -1,110 +1,5 @@
|
|
1
|
-
include_set Abstract::
|
1
|
+
include_set Abstract::Reflection
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
event :validate_list_item_type_change, :validate,
|
8
|
-
on: :save, changed: :name do
|
9
|
-
item_cards.each do |item_card|
|
10
|
-
next unless item_card.type_name.key != item_type_name.key
|
11
|
-
errors.add :name, t(:mirror_conflict_item_type)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
event :validate_list_content, :validate,
|
16
|
-
on: :save, changed: :content do
|
17
|
-
item_cards.each do |item_card|
|
18
|
-
next unless item_card.type_name.key != item_type_name.key
|
19
|
-
errors.add :content, t(
|
20
|
-
:mirror_only_type_allowed,
|
21
|
-
cardname: item_card.name,
|
22
|
-
cardtype: name.right
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
event :create_listed_by_cards, :prepare_to_validate,
|
28
|
-
on: :save, changed: :content do
|
29
|
-
item_names.each do |item_name|
|
30
|
-
listed_by_name = "#{item_name}+#{left.type_name}"
|
31
|
-
next if director.main_director.card.key == listed_by_name.to_name.key
|
32
|
-
if !Card[listed_by_name]
|
33
|
-
add_subcard listed_by_name, type_id: Card::MirrorListID
|
34
|
-
else
|
35
|
-
Card[listed_by_name].update_references_out
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
event :update_related_listed_by_card_on_create, :finalize, on: :create do
|
41
|
-
update_listed_by_cache_for item_keys
|
42
|
-
end
|
43
|
-
|
44
|
-
event :update_related_listed_by_card_on_content_update, :finalize,
|
45
|
-
on: :update, changed: :content do
|
46
|
-
new_items = item_keys
|
47
|
-
changed_items =
|
48
|
-
if db_content_before_act
|
49
|
-
old_items = item_keys(content: db_content_before_act)
|
50
|
-
old_items + new_items - (old_items & new_items)
|
51
|
-
else
|
52
|
-
new_items
|
53
|
-
end
|
54
|
-
update_listed_by_cache_for changed_items
|
55
|
-
end
|
56
|
-
|
57
|
-
event :update_related_listed_by_card_on_name_and_type_changes, :finalize,
|
58
|
-
on: :update, changed: %i[name type_id] do
|
59
|
-
update_all_items
|
60
|
-
end
|
61
|
-
|
62
|
-
event :update_related_listed_by_card_on_delete, :finalize,
|
63
|
-
on: :delete, when: :compound? do
|
64
|
-
update_listed_by_cache_for item_keys, type_key: @left_type_key
|
65
|
-
end
|
66
|
-
|
67
|
-
event :cache_type_key, :store, on: :delete, when: :compound? do
|
68
|
-
@left_type_key = left.type_card.key
|
69
|
-
end
|
70
|
-
|
71
|
-
def update_all_items
|
72
|
-
current_items = item_keys
|
73
|
-
if db_content_before_act
|
74
|
-
old_items = item_keys(content: db_content_before_act)
|
75
|
-
update_listed_by_cache_for old_items
|
76
|
-
end
|
77
|
-
update_listed_by_cache_for current_items
|
78
|
-
end
|
79
|
-
|
80
|
-
def update_listed_by_cache_for item_keys, args={}
|
81
|
-
type_key = args[:type_key] || left&.type_card&.key
|
82
|
-
return unless type_key
|
83
|
-
|
84
|
-
item_keys.each do |item_key|
|
85
|
-
key = "#{item_key}+#{type_key}"
|
86
|
-
next unless Card::Cache[Card::Set::Type::MirrorList].exist? key
|
87
|
-
if (card = Card.fetch(key)) && card.left
|
88
|
-
card.update_cached_list
|
89
|
-
card.update_references_out
|
90
|
-
else
|
91
|
-
Card::Cache[Card::Set::Type::MirrorList].delete key
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def item_type
|
97
|
-
name.right
|
98
|
-
end
|
99
|
-
|
100
|
-
def item_type_name
|
101
|
-
name.right_name
|
102
|
-
end
|
103
|
-
|
104
|
-
def item_type_card
|
105
|
-
name.right
|
106
|
-
end
|
107
|
-
|
108
|
-
def item_type_id
|
109
|
-
right.id
|
3
|
+
def mirroring_type
|
4
|
+
:mirror_list
|
110
5
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: card-mod-mirror
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Philipp Kühl
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-12-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: card
|
@@ -33,6 +33,7 @@ extensions: []
|
|
33
33
|
extra_rdoc_files: []
|
34
34
|
files:
|
35
35
|
- README.md
|
36
|
+
- set/abstract/reflection.rb
|
36
37
|
- set/all/list_changes.rb
|
37
38
|
- set/type/mirror_list.rb
|
38
39
|
- set/type/mirrored_list.rb
|
@@ -56,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
57
|
- !ruby/object:Gem::Version
|
57
58
|
version: '0'
|
58
59
|
requirements: []
|
59
|
-
rubygems_version: 3.2.
|
60
|
+
rubygems_version: 3.2.15
|
60
61
|
signing_key:
|
61
62
|
specification_version: 4
|
62
63
|
summary: mirror
|