card 1.16.15 → 1.17.0
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/config/initializers/recaptcha.rb +21 -4
- data/db/migrate_core_cards/20130823192433_add_style_cards.rb +1 -1
- data/db/migrate_core_cards/20140512155840_add_script_cards.rb +1 -1
- data/db/migrate_core_cards/20140629222005_add_email_cards.rb +2 -2
- data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +1 -1
- data/db/migrate_core_cards/20150528084659_add_session_cardtype.rb +1 -1
- data/db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb +63 -0
- data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +1 -1
- data/db/migrate_core_cards/20150903130006_attachment_upload_cards.rb +1 -1
- data/db/schema.rb +1 -1
- data/db/seed/new/card_actions.yml +602 -394
- data/db/seed/new/card_acts.yml +595 -1
- data/db/seed/new/card_changes.yml +26282 -10262
- data/db/seed/new/card_references.yml +1252 -1084
- data/db/seed/new/cards.yml +1899 -1423
- data/db/seed/test/fixtures/card_actions.yml +1653 -1413
- data/db/seed/test/fixtures/card_acts.yml +1063 -445
- data/db/seed/test/fixtures/card_changes.yml +29674 -13637
- data/db/seed/test/fixtures/card_references.yml +1976 -1815
- data/db/seed/test/fixtures/cards.yml +3194 -2719
- data/lib/card.rb +14 -13
- data/lib/card/auth.rb +10 -6
- data/lib/card/cache.rb +58 -120
- data/lib/card/cache/persistent.rb +50 -0
- data/lib/card/cache/temporary.rb +38 -0
- data/lib/card/chunk.rb +34 -25
- data/lib/card/content.rb +3 -3
- data/lib/card/env.rb +3 -0
- data/lib/card/format.rb +56 -53
- data/lib/card/migration.rb +6 -2
- data/lib/card/name.rb +9 -1
- data/lib/card/query.rb +1 -1
- data/lib/card/reference.rb +17 -11
- data/lib/card/set.rb +1 -1
- data/lib/card/subcards.rb +6 -6
- data/lib/card/view_cache.rb +45 -28
- data/lib/generators/card/migration/templates/card_migration.erb +1 -2
- data/mod/01_core/chunk/include.rb +71 -48
- data/mod/01_core/chunk/link.rb +6 -3
- data/mod/01_core/chunk/query_reference.rb +38 -29
- data/mod/01_core/chunk/reference.rb +23 -24
- data/mod/01_core/set/all/collection.rb +1 -1
- data/mod/01_core/set/all/fetch.rb +39 -12
- data/mod/01_core/set/all/permissions.rb +2 -4
- data/mod/01_core/set/all/references.rb +50 -75
- data/mod/01_core/set/all/rules.rb +19 -18
- data/mod/01_core/set/all/subcards.rb +1 -1
- data/mod/01_core/set/all/templating.rb +31 -88
- data/mod/01_core/set/all/tracked_attributes.rb +7 -14
- data/mod/01_core/set/all/utils.rb +77 -66
- data/mod/01_core/set_pattern/07_type_plus_right.rb +6 -3
- data/mod/01_core/spec/set/all/fetch_spec.rb +148 -96
- data/mod/01_core/spec/set/all/templating_spec.rb +49 -40
- data/mod/01_core/spec/set/all/trash_spec.rb +1 -1
- data/mod/01_history/set/all/actions.rb +1 -1
- data/mod/02_basic_types/set/all/base.rb +13 -7
- data/mod/02_basic_types/set/all/rss.rb +17 -22
- data/mod/02_basic_types/set/type/plain_text.rb +5 -2
- data/mod/02_basic_types/spec/set/all/base_spec.rb +1 -0
- data/mod/02_basic_types/spec/set/all/rss_spec.rb +7 -6
- data/mod/03_machines/lib/javascript/wagn.js.coffee +22 -9
- data/mod/03_machines/set/right/machine_output.rb +1 -1
- data/mod/04_settings/lib/card/setting.rb +45 -31
- data/mod/04_settings/set/right/structure.rb +47 -1
- data/mod/04_settings/set/self/default_html_view.rb +2 -0
- data/mod/04_settings/set/self/follow_fields.rb +2 -0
- data/mod/04_settings/set/self/recent_settings.rb +1 -1
- data/mod/05_standard/file/favicon/image-icon.png +0 -0
- data/mod/05_standard/file/favicon/image-large.png +0 -0
- data/mod/05_standard/file/favicon/image-medium.png +0 -0
- data/mod/05_standard/file/favicon/image-original.png +0 -0
- data/mod/05_standard/file/favicon/image-small.png +0 -0
- data/mod/05_standard/set/all/links.rb +27 -26
- data/mod/05_standard/set/all/rich_html/editing.rb +1 -1
- data/mod/05_standard/set/all/rich_html/toolbar.rb +1 -1
- data/mod/05_standard/set/rstar/rules.rb +20 -325
- data/mod/05_standard/set/rstar/rules_editor.rb +362 -0
- data/mod/05_standard/set/self/admin_info.rb +82 -0
- data/mod/05_standard/set/self/all.rb +16 -10
- data/mod/05_standard/set/self/head.rb +20 -19
- data/mod/05_standard/set/type/signup.rb +0 -1
- data/mod/05_standard/spec/set/all/account_spec.rb +44 -43
- data/mod/05_standard/spec/set/right/account_spec.rb +4 -2
- data/mod/05_standard/spec/set/type/search_type_spec.rb +8 -0
- data/mod/05_standard/spec/set/type/signup_spec.rb +24 -17
- data/mod/06_bootstrap/set/all/bootstrap/helper.rb +1 -1
- data/spec/lib/card/cache_spec.rb +64 -70
- data/spec/lib/card/content_spec.rb +236 -150
- data/spec/lib/card/reference_spec.rb +22 -38
- data/spec/lib/card/subcards_spec.rb +38 -0
- data/spec/lib/card/view_cache_spec.rb +8 -0
- data/spec/spec_helper.rb +1 -1
- data/tmpsets/set/mod001-01_core/all/collection.rb +77 -74
- data/tmpsets/set/mod001-01_core/all/content.rb +14 -16
- data/tmpsets/set/mod001-01_core/all/fetch.rb +137 -110
- data/tmpsets/set/mod001-01_core/all/name.rb +58 -40
- data/tmpsets/set/mod001-01_core/all/pattern.rb +12 -11
- data/tmpsets/set/mod001-01_core/all/permissions.rb +125 -117
- data/tmpsets/set/mod001-01_core/all/phases.rb +2 -1
- data/tmpsets/set/mod001-01_core/all/references.rb +52 -77
- data/tmpsets/set/mod001-01_core/all/rules.rb +47 -53
- data/tmpsets/set/mod001-01_core/all/templating.rb +31 -87
- data/tmpsets/set/mod001-01_core/all/tracked_attributes.rb +12 -21
- data/tmpsets/set/mod001-01_core/all/trash.rb +4 -1
- data/tmpsets/set/mod001-01_core/all/type.rb +23 -21
- data/tmpsets/set/mod001-01_core/all/utils.rb +80 -64
- data/tmpsets/set/mod002-01_history/all/actions.rb +20 -16
- data/tmpsets/set/mod002-01_history/all/history.rb +18 -13
- data/tmpsets/set/mod003-02_basic_types/all/base.rb +37 -10
- data/tmpsets/set/mod003-02_basic_types/all/rss.rb +17 -22
- data/tmpsets/set/mod003-02_basic_types/type/plain_text.rb +5 -2
- data/tmpsets/set/mod003-02_basic_types/type/pointer.rb +51 -39
- data/tmpsets/set/mod004-03_machines/right/machine_output.rb +10 -6
- data/tmpsets/set/mod005-04_settings/abstract/permission.rb +10 -5
- data/tmpsets/set/mod005-04_settings/right/structure.rb +47 -1
- data/tmpsets/set/mod005-04_settings/self/recent_settings.rb +1 -0
- data/tmpsets/set/mod005-04_settings/type/setting.rb +4 -1
- data/tmpsets/set/mod006-05_email/all/follow.rb +45 -54
- data/tmpsets/set/mod006-05_email/all/notify.rb +88 -73
- data/tmpsets/set/mod006-05_email/right/followers.rb +17 -14
- data/tmpsets/set/mod006-05_email/self/follow_defaults.rb +22 -18
- data/tmpsets/set/mod006-05_email/type/email_template.rb +1 -1
- data/tmpsets/set/mod007-05_standard/abstract/attachment.rb +94 -67
- data/tmpsets/set/mod007-05_standard/all/account.rb +18 -20
- data/tmpsets/set/mod007-05_standard/all/comment.rb +51 -29
- data/tmpsets/set/mod007-05_standard/all/error.rb +129 -99
- data/tmpsets/set/mod007-05_standard/all/links.rb +27 -26
- data/tmpsets/set/mod007-05_standard/all/rich_html/content.rb +115 -103
- data/tmpsets/set/mod007-05_standard/all/rich_html/editing.rb +112 -78
- data/tmpsets/set/mod007-05_standard/all/rich_html/form.rb +123 -81
- data/tmpsets/set/mod007-05_standard/all/rich_html/modal.rb +15 -58
- data/tmpsets/set/mod007-05_standard/all/rich_html/toolbar.rb +2 -2
- data/tmpsets/set/mod007-05_standard/right/account.rb +71 -75
- data/tmpsets/set/mod007-05_standard/right/email.rb +16 -13
- data/tmpsets/set/mod007-05_standard/right/password.rb +20 -12
- data/tmpsets/set/mod007-05_standard/right/status.rb +2 -2
- data/tmpsets/set/mod007-05_standard/right/token.rb +49 -2
- data/tmpsets/set/mod007-05_standard/rstar/rules.rb +20 -325
- data/tmpsets/set/mod007-05_standard/self/all.rb +16 -10
- data/tmpsets/set/mod007-05_standard/self/head.rb +76 -62
- data/tmpsets/set/mod007-05_standard/self/search.rb +45 -22
- data/tmpsets/set/mod007-05_standard/self/signin.rb +14 -12
- data/tmpsets/set/mod007-05_standard/type/cardtype.rb +13 -11
- data/tmpsets/set/mod007-05_standard/type/file.rb +1 -1
- data/tmpsets/set/mod007-05_standard/type/search_type.rb +3 -2
- data/tmpsets/set/mod007-05_standard/type/set.rb +20 -16
- data/tmpsets/set/mod007-05_standard/type/signup.rb +19 -25
- data/tmpsets/set/mod007-05_standard/type/user.rb +1 -1
- data/tmpsets/set/mod008-06_bootstrap/all/bootstrap/helper.rb +1 -1
- data/tmpsets/set_pattern/106-type_plus_right.rb +6 -3
- metadata +11 -2
data/lib/card/content.rb
CHANGED
@@ -50,8 +50,8 @@ class Card
|
|
50
50
|
when Array then each { |e| yield e if e.is_a?(Chunk::Abstract) }
|
51
51
|
when String # noop. strings are parsed in self, so no chunks in a String
|
52
52
|
else
|
53
|
-
Rails.logger.warn
|
54
|
-
|
53
|
+
Rails.logger.warn 'error self is unrecognized type' \
|
54
|
+
" #{self.class} #{__getobj__.class}"
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -59,7 +59,7 @@ class Card
|
|
59
59
|
each_chunk.select { |chunk| chunk.is_a?(chunk_type) }
|
60
60
|
end
|
61
61
|
|
62
|
-
def
|
62
|
+
def process_each_chunk &block
|
63
63
|
each_chunk { |chunk| chunk.process_chunk &block }
|
64
64
|
self
|
65
65
|
end
|
data/lib/card/env.rb
CHANGED
data/lib/card/format.rb
CHANGED
@@ -12,7 +12,7 @@ class Card
|
|
12
12
|
# FIXME: should be set in views
|
13
13
|
|
14
14
|
cattr_accessor :ajax_call, :registered
|
15
|
-
[:perms, :
|
15
|
+
[:perms, :denial, :closed, :error_code, :view_tags, :aliases
|
16
16
|
].each do |accessor_name|
|
17
17
|
cattr_accessor accessor_name
|
18
18
|
send "#{accessor_name}=", {}
|
@@ -37,10 +37,10 @@ class Card
|
|
37
37
|
|
38
38
|
def extract_class_vars view, opts
|
39
39
|
return unless opts.present?
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
[:perms, :error_code, :denial, :closed].each do |varname|
|
41
|
+
class_var = send varname
|
42
|
+
class_var[view] = opts.delete(varname) if opts[varname]
|
43
|
+
end
|
44
44
|
extract_view_tags view, opts
|
45
45
|
end
|
46
46
|
|
@@ -183,16 +183,12 @@ class Card
|
|
183
183
|
end
|
184
184
|
|
185
185
|
def method_missing method, *opts, &proc
|
186
|
-
|
187
|
-
when /(_)?(optional_)?render(_(\w+))?/
|
186
|
+
if method =~ /(_)?(optional_)?render(_(\w+))?/
|
188
187
|
view = $3 ? $4 : opts.shift
|
189
188
|
args = opts[0] ? opts.shift.clone : {}
|
190
189
|
args.merge!(optional: true, default_visibility: opts.shift) if $2
|
191
190
|
args[:skip_permissions] = true if $1
|
192
191
|
render view, args
|
193
|
-
# when /^_view_(\w+)/
|
194
|
-
# view = @current_view || $1
|
195
|
-
# unsupported_view view
|
196
192
|
else
|
197
193
|
proc = proc { |*a| raw yield *a } if proc
|
198
194
|
response = root.template.send method, *opts, &proc
|
@@ -207,12 +203,14 @@ class Card
|
|
207
203
|
def render view, args={}
|
208
204
|
view = canonicalize_view view
|
209
205
|
return if hidden_view? view, args
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
206
|
+
view = ok_view view, args
|
207
|
+
current_view(view) do
|
208
|
+
args = default_render_args view, args
|
209
|
+
with_inclusion_mode view do
|
210
|
+
Card::ViewCache.fetch(self, view, args) do
|
211
|
+
method = view_method view, args
|
212
|
+
method.arity == 0 ? method.call : method.call(args)
|
213
|
+
end
|
216
214
|
end
|
217
215
|
end
|
218
216
|
rescue => e
|
@@ -296,6 +294,14 @@ class Card
|
|
296
294
|
end
|
297
295
|
end
|
298
296
|
|
297
|
+
def current_view view
|
298
|
+
old_view = @current_view
|
299
|
+
@current_view = view
|
300
|
+
yield
|
301
|
+
ensure
|
302
|
+
@current_view = old_view
|
303
|
+
end
|
304
|
+
|
299
305
|
def error_cardname
|
300
306
|
card && card.name.present? ? card.name : 'unknown card'
|
301
307
|
end
|
@@ -319,19 +325,14 @@ class Card
|
|
319
325
|
mainline: @mainline, form: @form
|
320
326
|
end
|
321
327
|
|
322
|
-
def process_content
|
323
|
-
process_content_object(
|
328
|
+
def process_content override_content=nil, opts={}
|
329
|
+
process_content_object(override_content, opts).to_s
|
324
330
|
end
|
325
331
|
|
326
|
-
def process_content_object
|
327
|
-
|
328
|
-
content = card.raw_content || '' if content.nil?
|
332
|
+
def process_content_object override_content=nil, opts={}
|
333
|
+
content = override_content || render_raw || ''
|
329
334
|
content_object = get_content_object content, opts
|
330
|
-
|
331
|
-
# FIXME: should be handled with method on Card
|
332
|
-
card.update_references content_object, true
|
333
|
-
end
|
334
|
-
content_object.process_content_object do |chunk_opts|
|
335
|
+
content_object.process_each_chunk do |chunk_opts|
|
335
336
|
prepare_nest chunk_opts.merge(opts) { yield }
|
336
337
|
end
|
337
338
|
end
|
@@ -346,32 +347,34 @@ class Card
|
|
346
347
|
|
347
348
|
def ok_view view, args={}
|
348
349
|
return view if args.delete :skip_permissions
|
349
|
-
approved_view =
|
350
|
-
case
|
351
|
-
when @depth >= Card.config.max_depth
|
352
|
-
# prevent recursion. @depth tracks subformats
|
353
|
-
:too_deep
|
354
|
-
when @@perms[view] == :none
|
355
|
-
# permission skipping specified in view definition
|
356
|
-
view
|
357
|
-
when args.delete(:skip_permissions)
|
358
|
-
# permission skipping specified in args
|
359
|
-
view
|
360
|
-
when !card.known? && !tagged(view, :unknown_ok)
|
361
|
-
# handle unknown cards (where view not exempt)
|
362
|
-
view_for_unknown view, args
|
363
|
-
else
|
364
|
-
# run explicit permission checks
|
365
|
-
permitted_view view, args
|
366
|
-
end
|
367
|
-
|
350
|
+
approved_view = approved_view view, args
|
368
351
|
args[:denied_view] = view if approved_view != view
|
369
|
-
if focal? && (error_code = @@
|
352
|
+
if focal? && (error_code = @@error_code[approved_view])
|
370
353
|
root.error_status = error_code
|
371
354
|
end
|
372
355
|
approved_view
|
373
356
|
end
|
374
357
|
|
358
|
+
def approved_view view, args={}
|
359
|
+
case
|
360
|
+
when @depth >= Card.config.max_depth
|
361
|
+
# prevent recursion. @depth tracks subformats
|
362
|
+
:too_deep
|
363
|
+
when @@perms[view] == :none
|
364
|
+
# permission skipping specified in view definition
|
365
|
+
view
|
366
|
+
when args.delete(:skip_permissions)
|
367
|
+
# permission skipping specified in args
|
368
|
+
view
|
369
|
+
when !card.known? && !tagged(view, :unknown_ok)
|
370
|
+
# handle unknown cards (where view not exempt)
|
371
|
+
view_for_unknown view, args
|
372
|
+
else
|
373
|
+
# run explicit permission checks
|
374
|
+
permitted_view view, args
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
375
378
|
def tagged view, tag
|
376
379
|
self.class.tagged view, tag
|
377
380
|
end
|
@@ -386,7 +389,7 @@ class Card
|
|
386
389
|
end
|
387
390
|
|
388
391
|
if args[:denied_task]
|
389
|
-
@@
|
392
|
+
@@denial[view] || :denial
|
390
393
|
else
|
391
394
|
view
|
392
395
|
end
|
@@ -511,13 +514,13 @@ class Card
|
|
511
514
|
end
|
512
515
|
|
513
516
|
def view_in_closed_mode homeview, nested_card
|
514
|
-
approved_view = @@
|
517
|
+
approved_view = @@closed[homeview]
|
515
518
|
case
|
516
|
-
when approved_view == true
|
517
|
-
when @@
|
518
|
-
when approved_view
|
519
|
-
when !nested_card.known?
|
520
|
-
else
|
519
|
+
when approved_view == true then homeview
|
520
|
+
when @@error_code[homeview] then homeview
|
521
|
+
when approved_view then approved_view
|
522
|
+
when !nested_card.known? then :closed_missing
|
523
|
+
else :closed_content
|
521
524
|
end
|
522
525
|
end
|
523
526
|
|
data/lib/card/migration.rb
CHANGED
@@ -63,14 +63,14 @@ class Card::Migration < ActiveRecord::Migration
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def contentedly
|
66
|
-
Card::Cache.
|
66
|
+
Card::Cache.reset_all
|
67
67
|
Cardio.schema_mode '' do
|
68
68
|
Card::Auth.as_bot do
|
69
69
|
ActiveRecord::Base.transaction do
|
70
70
|
begin
|
71
71
|
yield
|
72
72
|
ensure
|
73
|
-
Card::Cache.
|
73
|
+
Card::Cache.reset_all
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -122,6 +122,10 @@ class Card::Migration < ActiveRecord::Migration
|
|
122
122
|
def down
|
123
123
|
raise ActiveRecord::IrreversibleMigration
|
124
124
|
end
|
125
|
+
|
126
|
+
def update_machine_output
|
127
|
+
Card.search(right: { codename: 'machine_output' }).each(&:delete)
|
128
|
+
end
|
125
129
|
end
|
126
130
|
|
127
131
|
require 'card/core_migration'
|
data/lib/card/name.rb
CHANGED
@@ -74,7 +74,7 @@ class Card
|
|
74
74
|
to_absolute_name(context_name)
|
75
75
|
end
|
76
76
|
|
77
|
-
def
|
77
|
+
def child_of? context_name
|
78
78
|
if context_name.present?
|
79
79
|
# Do I still equal myself after I've been relativised in the context
|
80
80
|
# of context_name?
|
@@ -84,6 +84,14 @@ class Card
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
def field_of? context_name
|
88
|
+
if context_name.present?
|
89
|
+
child_of?(context_name) && relative_name(context_name).length == 2
|
90
|
+
else
|
91
|
+
s.match(/^\s*\+[^+]+$/)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
87
95
|
def setting?
|
88
96
|
Set::Type::Setting.member_names[key]
|
89
97
|
end
|
data/lib/card/query.rb
CHANGED
@@ -46,7 +46,7 @@ class Card
|
|
46
46
|
|
47
47
|
ATTRIBUTES = {
|
48
48
|
basic: %w( id name key type_id content left_id right_id
|
49
|
-
creator_id updater_id codename
|
49
|
+
creator_id updater_id codename read_rule_id ),
|
50
50
|
relational: %w( type part left right
|
51
51
|
editor_of edited_by last_editor_of last_edited_by
|
52
52
|
creator_of created_by member_of member ),
|
data/lib/card/reference.rb
CHANGED
@@ -10,28 +10,27 @@ class Card::Reference < ActiveRecord::Base
|
|
10
10
|
end
|
11
11
|
|
12
12
|
class << self
|
13
|
-
|
14
13
|
def delete_all_from card
|
15
14
|
delete_all referer_id: card.id
|
16
15
|
end
|
17
16
|
|
18
17
|
def delete_all_to card
|
19
|
-
where(
|
18
|
+
where(referee_id: card.id).update_all present: 0, referee_id: nil
|
20
19
|
end
|
21
20
|
|
22
21
|
def update_existing_key card, name=nil
|
23
22
|
key = (name || card.name).to_name.key
|
24
|
-
where(
|
23
|
+
where(referee_key: key).update_all present: 1, referee_id: card.id
|
25
24
|
end
|
26
25
|
|
27
26
|
def update_on_rename card, newname, update_referers=false
|
28
27
|
if update_referers
|
29
|
-
# not
|
30
|
-
#
|
28
|
+
# not currently needed because references are deleted and re-created
|
29
|
+
# in the process of adding new revision
|
30
|
+
# where referee_id: card.id).update_all referee_key: newname.to_name.key
|
31
31
|
else
|
32
32
|
delete_all_to card
|
33
33
|
end
|
34
|
-
#Rails.logger.warn "update on rename #{card.inspect}, #{newname}, #{update_referers}"
|
35
34
|
update_existing_key card, newname
|
36
35
|
end
|
37
36
|
|
@@ -41,22 +40,29 @@ class Card::Reference < ActiveRecord::Base
|
|
41
40
|
end
|
42
41
|
|
43
42
|
def repair_missing_referees
|
44
|
-
joins(
|
43
|
+
joins(
|
44
|
+
'LEFT JOIN cards ON card_references.referee_id = cards.id'
|
45
|
+
).where(
|
46
|
+
'(cards.id IS NULL OR cards.trash IS TRUE) AND referee_id IS NOT NULL'
|
47
|
+
).update_all referee_id: nil
|
45
48
|
end
|
46
49
|
|
47
50
|
def delete_missing_referers
|
48
|
-
joins(
|
51
|
+
joins(
|
52
|
+
'LEFT JOIN cards ON card_references.referer_id = cards.id'
|
53
|
+
).where(
|
54
|
+
'cards.id IS NULL OR cards.trash IS TRUE'
|
55
|
+
).delete_all
|
49
56
|
end
|
50
57
|
|
51
58
|
def repair_all
|
52
59
|
delete_missing_referers
|
53
60
|
|
54
61
|
Card.where(trash: false).find_each do |card|
|
55
|
-
Rails.logger.info "
|
62
|
+
Rails.logger.info "Repairing references for '#{card.name}'" \
|
63
|
+
"(id: #{card.id}) ... "
|
56
64
|
card.update_references
|
57
65
|
end
|
58
66
|
end
|
59
|
-
|
60
67
|
end
|
61
|
-
|
62
68
|
end
|
data/lib/card/set.rb
CHANGED
@@ -438,7 +438,7 @@ EOF
|
|
438
438
|
mod_traits = get_traits mod
|
439
439
|
|
440
440
|
new_opts = options[:type] ? { type: options[:type] } : {}
|
441
|
-
new_opts.merge!(
|
441
|
+
new_opts.merge!(default_content: options[:default]) if options[:default]
|
442
442
|
|
443
443
|
args.each do |trait|
|
444
444
|
define_trait_card trait, new_opts
|
data/lib/card/subcards.rb
CHANGED
@@ -15,18 +15,18 @@ class Card
|
|
15
15
|
|
16
16
|
def preserve_subcards
|
17
17
|
return unless subcards.present?
|
18
|
-
Card.cache.
|
18
|
+
Card.cache.soft.write subcards_cache_key, @subcards
|
19
19
|
end
|
20
20
|
|
21
21
|
def restore_subcards
|
22
|
-
cached_subcards = Card.cache.
|
22
|
+
cached_subcards = Card.cache.soft.read(subcards_cache_key)
|
23
23
|
return unless cached_subcards
|
24
24
|
@subcards = cached_subcards
|
25
25
|
@subcards.context_card = self
|
26
26
|
end
|
27
27
|
|
28
28
|
def expire_subcards
|
29
|
-
Card.cache.
|
29
|
+
Card.cache.soft.delete subcards_cache_key
|
30
30
|
subcards.clear
|
31
31
|
end
|
32
32
|
|
@@ -43,7 +43,7 @@ class Card
|
|
43
43
|
|
44
44
|
def clear
|
45
45
|
@keys.each do |key|
|
46
|
-
Card.cache.
|
46
|
+
Card.cache.soft.delete key
|
47
47
|
end
|
48
48
|
@keys = ::Set.new
|
49
49
|
end
|
@@ -61,7 +61,7 @@ class Card
|
|
61
61
|
key = absolutize_subcard_name(key).key unless @keys.include?(key)
|
62
62
|
@keys.delete key
|
63
63
|
removed_card = fetch_subcard key
|
64
|
-
Card.cache.
|
64
|
+
Card.cache.soft.delete key
|
65
65
|
removed_card
|
66
66
|
end
|
67
67
|
|
@@ -239,7 +239,7 @@ class Card
|
|
239
239
|
card.superleft = @context_card
|
240
240
|
end
|
241
241
|
@keys << card.key
|
242
|
-
Card.
|
242
|
+
Card.write_to_soft_cache card
|
243
243
|
card
|
244
244
|
end
|
245
245
|
end
|
data/lib/card/view_cache.rb
CHANGED
@@ -10,11 +10,42 @@ class Card
|
|
10
10
|
Card::Cache[Card::ViewCache]
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
13
|
+
def fetch format, view, args, &block
|
14
|
+
return block.call if cacheable_view?(view, format)
|
15
|
+
|
16
|
+
key = cache_key view, format, args
|
17
|
+
if !cache.exist?(key)
|
18
|
+
increment_cached_views_cnt
|
19
|
+
reduce_cache if cached_views_cnt > LIMIT
|
20
|
+
end
|
21
|
+
increment_frequency key
|
22
|
+
|
23
|
+
if Card.config.view_cache == 'debug'
|
24
|
+
verbose_fetch key, &bloack
|
25
|
+
else
|
26
|
+
cache.fetch key, &block
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def reset
|
31
|
+
cache.reset
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def verbose_fetch
|
37
|
+
if cache.exist? key
|
38
|
+
"fetched from view cache: #{cache.read key}"
|
39
|
+
else
|
40
|
+
"written to view cache: #{cache.fetch(key, &block)}"
|
41
|
+
end
|
15
42
|
end
|
16
43
|
|
17
|
-
def
|
44
|
+
def increment_cached_views_cnt
|
45
|
+
cache.write(CNT_KEY, cached_views_cnt + 1)
|
46
|
+
end
|
47
|
+
|
48
|
+
def cached_views_cnt
|
18
49
|
cache.read(CNT_KEY) || 0
|
19
50
|
end
|
20
51
|
|
@@ -22,7 +53,7 @@ class Card
|
|
22
53
|
update_frequency do |freq|
|
23
54
|
cnts_with_key = freq.keys.map { |key| [freq[key], key] }
|
24
55
|
index = 1
|
25
|
-
SortedSet.new(cnts_with_key).each do |
|
56
|
+
SortedSet.new(cnts_with_key).each do |_cnt, key|
|
26
57
|
if index < (LIMIT - SIZE)
|
27
58
|
cache.delete(key)
|
28
59
|
freq.delete(key)
|
@@ -40,37 +71,23 @@ class Card
|
|
40
71
|
cache.write(FREQUENCY_KEY, freq)
|
41
72
|
end
|
42
73
|
|
43
|
-
def
|
44
|
-
if !Card.config.view_cache || !format.view_caching? || !format.main? || (view != :open && view != :content) || format.class != HtmlFormat
|
45
|
-
return block.call
|
46
|
-
end
|
47
|
-
|
48
|
-
roles = Card::Auth.current.all_roles.sort.join '_'
|
49
|
-
key = "view_#{view}_#{format.card.key}_args_#{Card::Cache.obj_to_key(args)}_roles_#{roles}"
|
50
|
-
|
51
|
-
if !cache.exist?(key)
|
52
|
-
increment_cnt
|
53
|
-
reduce_cache if count > LIMIT
|
54
|
-
end
|
55
|
-
|
74
|
+
def increment_frequency key
|
56
75
|
update_frequency do |freq|
|
57
76
|
freq[key] ||= 0
|
58
77
|
freq[key] += 1
|
59
78
|
end
|
79
|
+
end
|
60
80
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
67
|
-
else
|
68
|
-
cache.fetch(key, &block)
|
69
|
-
end
|
81
|
+
def cache_key view, format, args
|
82
|
+
roles_key = Card::Auth.current.all_roles.sort.join '_'
|
83
|
+
args_key = Card::Cache.obj_to_key(args)
|
84
|
+
'%s#%s__args__%s__roles__%s' %
|
85
|
+
[format.card.key, view, args_key, roles_key]
|
70
86
|
end
|
71
87
|
|
72
|
-
def
|
73
|
-
|
88
|
+
def cacheable_view? view, format
|
89
|
+
!Card.config.view_cache || !format.view_caching? || !format.main? ||
|
90
|
+
(view != :open && view != :content) || format.class != HtmlFormat
|
74
91
|
end
|
75
92
|
end
|
76
93
|
end
|