card 1.16.10 → 1.16.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/db/migrate/20151105225559_more_space_for_db_content.rb +6 -0
- data/db/migrate_core_cards/20150708224756_add_list_cards.rb +19 -12
- data/db/schema.rb +11 -11
- data/db/version.txt +1 -1
- data/lib/card/active_record_helper.rb +9 -11
- data/lib/card/cache.rb +18 -18
- data/mod/01_core/set/all/fetch.rb +14 -15
- data/mod/01_core/set/all/name.rb +46 -38
- data/mod/01_core/set/all/references.rb +1 -1
- data/mod/01_core/set/all/subcards.rb +1 -1
- data/mod/01_core/set/all/tracked_attributes.rb +4 -6
- data/mod/01_core/set/all/trash.rb +4 -1
- data/mod/01_core/spec/set/all/fetch_spec.rb +12 -11
- data/mod/01_core/spec/set/all/tracked_attributes_spec.rb +145 -143
- data/mod/03_machines/lib/card/machine.rb +0 -1
- data/mod/05_standard/set/all/rich_html/editing.rb +38 -30
- data/mod/05_standard/set/right/account.rb +41 -22
- data/spec/models/card/cardtype_spec.rb +11 -27
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87ac13203770cb0105dca6d10755c9f442425230
|
4
|
+
data.tar.gz: 4f27287e05a9cb4ed93e0dd18a64585d47b9f044
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94d18bfbd1b5ffc9ae65f3cc503006571569b9a2b483bfe2b412b7d73d760e121d34dacd23e36bd21930e03145e943e9e29863f8fedbe96884d6b204e4ce5a0b
|
7
|
+
data.tar.gz: 6d01d13ce7cd4e0c3e0a88414ee9f384e1ce9641189a54bcf0e032dae75f3decfb2371a7e3bba8e77a3546cb026bbdbc0a8998b5a48e53162e8b44eb7c6e3581
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.16.
|
1
|
+
1.16.11
|
@@ -4,19 +4,26 @@ class AddListCards < Card::CoreMigration
|
|
4
4
|
def up
|
5
5
|
create_card! name: 'List', codename: :list,
|
6
6
|
type_code: :cardtype
|
7
|
+
|
7
8
|
create_card! name: 'Listed by', codename: :listed_by,
|
8
9
|
type_code: :cardtype
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
|
11
|
+
create_or_update name: '*cached count',
|
12
|
+
codename: :cached_count,
|
13
|
+
rename_if_conflict: false,
|
14
|
+
subcards: {
|
15
|
+
'+*right+*update' => '[[Administrator]]',
|
16
|
+
'+*right+*create' => '[[Administrator]]',
|
17
|
+
'+*right+*delete' => '[[Administrator]]'
|
18
|
+
}
|
19
|
+
|
20
|
+
create_or_update name: '*cached content',
|
21
|
+
codename: :cached_content,
|
22
|
+
rename_if_conflict: false,
|
23
|
+
subcards: {
|
24
|
+
'+*right+*update' => '[[Administrator]]',
|
25
|
+
'+*right+*create' => '[[Administrator]]',
|
26
|
+
'+*right+*delete' => '[[Administrator]]'
|
27
|
+
}
|
21
28
|
end
|
22
29
|
end
|
data/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20151105225559) do
|
15
15
|
|
16
16
|
create_table "card_actions", force: :cascade do |t|
|
17
17
|
t.integer "card_id", limit: 4
|
@@ -38,7 +38,7 @@ ActiveRecord::Schema.define(version: 20150724210803) do
|
|
38
38
|
create_table "card_changes", force: :cascade do |t|
|
39
39
|
t.integer "card_action_id", limit: 4
|
40
40
|
t.integer "field", limit: 4
|
41
|
-
t.text "value", limit:
|
41
|
+
t.text "value", limit: 16777215
|
42
42
|
end
|
43
43
|
|
44
44
|
add_index "card_changes", ["card_action_id"], name: "card_changes_card_action_id_index", using: :btree
|
@@ -66,22 +66,22 @@ ActiveRecord::Schema.define(version: 20150724210803) do
|
|
66
66
|
add_index "card_revisions", ["creator_id"], name: "revisions_created_by_index", using: :btree
|
67
67
|
|
68
68
|
create_table "cards", force: :cascade do |t|
|
69
|
-
t.string "name", limit: 255,
|
70
|
-
t.string "key", limit: 255,
|
69
|
+
t.string "name", limit: 255, null: false
|
70
|
+
t.string "key", limit: 255, null: false
|
71
71
|
t.string "codename", limit: 255
|
72
72
|
t.integer "left_id", limit: 4
|
73
73
|
t.integer "right_id", limit: 4
|
74
74
|
t.integer "current_revision_id", limit: 4
|
75
|
-
t.datetime "created_at",
|
76
|
-
t.datetime "updated_at",
|
77
|
-
t.integer "creator_id", limit: 4,
|
78
|
-
t.integer "updater_id", limit: 4,
|
75
|
+
t.datetime "created_at", null: false
|
76
|
+
t.datetime "updated_at", null: false
|
77
|
+
t.integer "creator_id", limit: 4, null: false
|
78
|
+
t.integer "updater_id", limit: 4, null: false
|
79
79
|
t.string "read_rule_class", limit: 255
|
80
80
|
t.integer "read_rule_id", limit: 4
|
81
81
|
t.integer "references_expired", limit: 4
|
82
|
-
t.boolean "trash",
|
83
|
-
t.integer "type_id", limit: 4,
|
84
|
-
t.text "db_content", limit:
|
82
|
+
t.boolean "trash", null: false
|
83
|
+
t.integer "type_id", limit: 4, null: false
|
84
|
+
t.text "db_content", limit: 16777215
|
85
85
|
end
|
86
86
|
|
87
87
|
add_index "cards", ["key"], name: "cards_key_index", unique: true, using: :btree
|
data/db/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
20151105225559
|
@@ -5,7 +5,7 @@ module Card::ActiveRecordHelper
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def create_card! args
|
8
|
-
create_card args.
|
8
|
+
create_card args.reverse_merge(rename_if_conflict: :new)
|
9
9
|
end
|
10
10
|
|
11
11
|
def update_card name, args
|
@@ -14,7 +14,7 @@ module Card::ActiveRecordHelper
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def update_card! args
|
17
|
-
update_card args.
|
17
|
+
update_card args.reverse_merge(rename_if_conflict: :new)
|
18
18
|
end
|
19
19
|
|
20
20
|
def create_or_update name_or_args, args=nil
|
@@ -23,22 +23,20 @@ module Card::ActiveRecordHelper
|
|
23
23
|
if Card[name]
|
24
24
|
update_card name, args
|
25
25
|
else
|
26
|
-
create_card args.merge(:name
|
26
|
+
create_card args.merge(name: name)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
def create_or_update! name_or_args, args=nil
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
name_or_args[:resolve_name_conflict] = :other
|
35
|
-
end
|
36
|
-
create_or_update name_or_args, args
|
31
|
+
name = args ? name_or_args : name_or_args[:name]
|
32
|
+
args ||= {}
|
33
|
+
create_or_update name, args.reverse_merge(rename_if_conflict: :new)
|
37
34
|
end
|
38
35
|
|
39
36
|
def resolve_name_conflict args
|
40
|
-
|
41
|
-
|
37
|
+
rename = args.delete :rename_if_conflict
|
38
|
+
if rename
|
39
|
+
args[:name] = Card.uniquify_name args[:name], rename
|
42
40
|
end
|
43
41
|
end
|
44
42
|
end
|
data/lib/card/cache.rb
CHANGED
@@ -54,11 +54,13 @@ class Card
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def generate_cache_id
|
57
|
-
((Time.now.to_f * 100).to_i).to_s +
|
57
|
+
((Time.now.to_f * 100).to_i).to_s +
|
58
|
+
('a'..'z').to_a[rand(26)] +
|
59
|
+
('a'..'z').to_a[rand(26)]
|
58
60
|
end
|
59
61
|
|
60
62
|
def reset_global
|
61
|
-
cache_by_class.each do |
|
63
|
+
cache_by_class.each do |_klass, cache|
|
62
64
|
cache.reset hard=true
|
63
65
|
end
|
64
66
|
Card::Codename.reset_cache
|
@@ -67,9 +69,11 @@ class Card
|
|
67
69
|
|
68
70
|
def reset_local
|
69
71
|
cache_by_class.each do |cc, cache|
|
70
|
-
if Card::Cache===cache
|
72
|
+
if Card::Cache === cache
|
71
73
|
cache.reset_local
|
72
|
-
else
|
74
|
+
else
|
75
|
+
warn "reset class #{cc}, #{cache.class} #{caller[0..8] * "\n"} ???"
|
76
|
+
end
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
@@ -91,20 +95,16 @@ class Card
|
|
91
95
|
private
|
92
96
|
|
93
97
|
def prepopulate
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
98
|
+
return unless @@prepopulating
|
99
|
+
@@rule_cache ||= Card.rule_cache
|
100
|
+
@@user_ids_cache ||= Card.user_ids_cache
|
101
|
+
@@read_rule_cache ||= Card.read_rule_cache
|
102
|
+
@@rule_keys_cache ||= Card.rule_keys_cache
|
103
|
+
Card.cache.write_local 'RULES', @@rule_cache
|
104
|
+
Card.cache.write_local 'READRULES', @@read_rule_cache
|
105
|
+
Card.cache.write_local 'USER_IDS', @@user_ids_cache
|
106
|
+
Card.cache.write_local 'RULE_KEYS', @@rule_keys_cache
|
104
107
|
end
|
105
|
-
|
106
|
-
|
107
|
-
|
108
108
|
end
|
109
109
|
|
110
110
|
attr_reader :prefix, :store, :klass
|
@@ -179,7 +179,7 @@ class Card
|
|
179
179
|
|
180
180
|
def delete key
|
181
181
|
@store.delete(@prefix + key) if @store
|
182
|
-
|
182
|
+
delete_local key
|
183
183
|
end
|
184
184
|
|
185
185
|
def delete_local key
|
@@ -210,10 +210,9 @@ module ClassMethods
|
|
210
210
|
end
|
211
211
|
|
212
212
|
def write_to_local_cache card
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
end
|
213
|
+
return unless Card.cache
|
214
|
+
Card.cache.write_local card.key, card
|
215
|
+
Card.cache.write_local "~#{card.id}", card.key if card.id && card.id != 0
|
217
216
|
end
|
218
217
|
|
219
218
|
def expand_mark mark, opts
|
@@ -242,7 +241,7 @@ module ClassMethods
|
|
242
241
|
end
|
243
242
|
end
|
244
243
|
|
245
|
-
def fullname_from_name name, new_opts
|
244
|
+
def fullname_from_name name, new_opts={}
|
246
245
|
if new_opts && supercard = new_opts[:supercard]
|
247
246
|
name.to_name.to_absolute_name supercard.name
|
248
247
|
else
|
@@ -253,16 +252,17 @@ end
|
|
253
252
|
|
254
253
|
# ~~~~~~~~~~ Instance ~~~~~~~~~~~~~
|
255
254
|
|
256
|
-
def fetch opts
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
255
|
+
def fetch opts={}
|
256
|
+
traits = opts.delete(:trait)
|
257
|
+
return unless traits
|
258
|
+
# should this fail as an incorrect api call?
|
259
|
+
traits = Array.wrap traits
|
260
|
+
traits.inject(self) do |card, trait|
|
261
|
+
Card.fetch card.cardname.trait(trait), opts
|
262
262
|
end
|
263
263
|
end
|
264
264
|
|
265
|
-
def renew args
|
265
|
+
def renew args={}
|
266
266
|
opts = args[:new].clone
|
267
267
|
opts[:name] ||= cardname
|
268
268
|
opts[:skip_modules] = args[:skip_modules]
|
@@ -275,7 +275,7 @@ def expire_pieces
|
|
275
275
|
end
|
276
276
|
end
|
277
277
|
|
278
|
-
def expire subcards
|
278
|
+
def expire subcards=false
|
279
279
|
# Rails.logger.warn "expiring i:#{id}, #{inspect}"
|
280
280
|
if subcards
|
281
281
|
expire_subcards
|
@@ -286,7 +286,7 @@ def expire subcards = false
|
|
286
286
|
Card.cache.delete "~#{id}" if id
|
287
287
|
end
|
288
288
|
|
289
|
-
def refresh force
|
289
|
+
def refresh force=false
|
290
290
|
if force || self.frozen? || self.readonly?
|
291
291
|
fresh_card = self.class.find id
|
292
292
|
fresh_card.include_set_modules
|
@@ -308,4 +308,3 @@ def rename_from_mark mark
|
|
308
308
|
return unless mark && mark.to_s != name
|
309
309
|
self.name = mark.to_s
|
310
310
|
end
|
311
|
-
|
data/mod/01_core/set/all/name.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
require 'uuid'
|
2
2
|
|
3
3
|
module ClassMethods
|
4
|
-
def uniquify_name name, rename
|
5
|
-
return name unless Card
|
4
|
+
def uniquify_name name, rename=:new
|
5
|
+
return name unless Card.exists?(name)
|
6
6
|
uniq_name = "#{name} 1"
|
7
|
-
while Card
|
7
|
+
while Card.exists?(uniq_name)
|
8
8
|
uniq_name.next!
|
9
9
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
if rename == :old
|
11
|
+
# name conflict resolved; original name can be used
|
12
|
+
Card[name].update_attributes! name: uniq_name,
|
13
|
+
update_referencers: true
|
14
|
+
name
|
15
|
+
else
|
16
|
+
uniq_name
|
17
|
+
end
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -120,23 +122,32 @@ def left_or_new args={}
|
|
120
122
|
end
|
121
123
|
|
122
124
|
def children
|
123
|
-
|
125
|
+
children_names.map { |name| Card[name] }
|
124
126
|
end
|
125
127
|
|
126
|
-
def
|
127
|
-
|
128
|
+
def children_names parent_name=nil
|
129
|
+
# eg, A+B is a child of A and B
|
130
|
+
parent_name ||= name
|
131
|
+
field = parent_name.to_name.simple? ? :part : :left
|
132
|
+
Card.search field => parent_name, return: :name
|
133
|
+
end
|
128
134
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
# Rails.logger.warn "dependents[#{inspect}] #{@dependents.inspect}"
|
135
|
+
def descendant_names parent_name=nil
|
136
|
+
return [] if new_card?
|
137
|
+
parent_name ||= name
|
138
|
+
Auth.as_bot do
|
139
|
+
deps = children_names parent_name
|
140
|
+
deps.inject(deps) do |array, childname|
|
141
|
+
array + descendant_names(childname)
|
142
|
+
end
|
138
143
|
end
|
139
|
-
|
144
|
+
end
|
145
|
+
|
146
|
+
def descendants
|
147
|
+
# children and children's children
|
148
|
+
# NOTE - set modules are not loaded
|
149
|
+
# -- should only be used for name manipulations
|
150
|
+
@descendants ||= descendant_names.map { |name| Card.quick_fetch name }
|
140
151
|
end
|
141
152
|
|
142
153
|
def repair_key
|
@@ -154,7 +165,7 @@ def repair_key
|
|
154
165
|
saved ||= (self.cardname = current_key) && self.save!
|
155
166
|
|
156
167
|
if saved
|
157
|
-
|
168
|
+
descendants.each(&:repair_key)
|
158
169
|
else
|
159
170
|
Rails.logger.debug "FAILED TO REPAIR BROKEN KEY: #{key}"
|
160
171
|
self.name = "BROKEN KEY: #{name}"
|
@@ -275,28 +286,25 @@ event :cascade_name_changes, after: :store, on: :update, changed: :name do
|
|
275
286
|
self.update_referencers = false if update_referencers == 'false'
|
276
287
|
Card::Reference.update_on_rename self, name, self.update_referencers
|
277
288
|
|
278
|
-
|
279
|
-
|
280
|
-
# " #{deps.map(&:name)*', '} -----------------------"
|
281
|
-
|
282
|
-
@dependents = nil # reset
|
289
|
+
des = descendants
|
290
|
+
@descendants = nil # reset
|
283
291
|
|
284
|
-
|
292
|
+
des.each do |de|
|
285
293
|
# here we specifically want NOT to invoke recursive cascades on these
|
286
294
|
# cards, have to go this low level to avoid callbacks.
|
287
|
-
Rails.logger.info "cascading name: #{
|
288
|
-
Card.expire
|
289
|
-
newname =
|
290
|
-
Card.where(id:
|
291
|
-
Card::Reference.update_on_rename
|
295
|
+
Rails.logger.info "cascading name: #{de.name}"
|
296
|
+
Card.expire de.name # old name
|
297
|
+
newname = de.cardname.replace_part name_was, name
|
298
|
+
Card.where(id: de.id).update_all name: newname.to_s, key: newname.key
|
299
|
+
Card::Reference.update_on_rename de, newname, update_referencers
|
292
300
|
Card.expire newname
|
293
301
|
end
|
294
|
-
execute_referencers_update(
|
302
|
+
execute_referencers_update(des) if update_referencers
|
295
303
|
end
|
296
304
|
|
297
|
-
def execute_referencers_update
|
305
|
+
def execute_referencers_update descendants
|
298
306
|
Auth.as_bot do
|
299
|
-
[name_referencers(name_was) +
|
307
|
+
[name_referencers(name_was) + descendants.map(&:referencers)]
|
300
308
|
.flatten.uniq.each do |card|
|
301
309
|
# FIXME: using 'name_referencers' instead of plain 'referencers' for self
|
302
310
|
# because there are cases where trunk and tag
|
@@ -307,7 +315,7 @@ def execute_referencers_update dependents
|
|
307
315
|
# so at this time X is still including Y, which does not exist.
|
308
316
|
# therefore #referencers doesn't find it, but name_referencers(old_name)
|
309
317
|
# does.
|
310
|
-
# some even more complicated scenario probably breaks on the
|
318
|
+
# some even more complicated scenario probably breaks on the descendants,
|
311
319
|
# so this probably needs a more thoughtful refactor
|
312
320
|
# aligning the dependent saving with the name cascading
|
313
321
|
|