card 1.16.15 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/initializers/recaptcha.rb +21 -4
  4. data/db/migrate_core_cards/20130823192433_add_style_cards.rb +1 -1
  5. data/db/migrate_core_cards/20140512155840_add_script_cards.rb +1 -1
  6. data/db/migrate_core_cards/20140629222005_add_email_cards.rb +2 -2
  7. data/db/migrate_core_cards/20150202143810_import_bootstrap_layout.rb +1 -1
  8. data/db/migrate_core_cards/20150528084659_add_session_cardtype.rb +1 -1
  9. data/db/migrate_core_cards/20150610180019_add_recaptcha_key_and_admin_info_cards.rb +63 -0
  10. data/db/migrate_core_cards/20150724123438_update_file_and_image_cards.rb +1 -1
  11. data/db/migrate_core_cards/20150903130006_attachment_upload_cards.rb +1 -1
  12. data/db/schema.rb +1 -1
  13. data/db/seed/new/card_actions.yml +602 -394
  14. data/db/seed/new/card_acts.yml +595 -1
  15. data/db/seed/new/card_changes.yml +26282 -10262
  16. data/db/seed/new/card_references.yml +1252 -1084
  17. data/db/seed/new/cards.yml +1899 -1423
  18. data/db/seed/test/fixtures/card_actions.yml +1653 -1413
  19. data/db/seed/test/fixtures/card_acts.yml +1063 -445
  20. data/db/seed/test/fixtures/card_changes.yml +29674 -13637
  21. data/db/seed/test/fixtures/card_references.yml +1976 -1815
  22. data/db/seed/test/fixtures/cards.yml +3194 -2719
  23. data/lib/card.rb +14 -13
  24. data/lib/card/auth.rb +10 -6
  25. data/lib/card/cache.rb +58 -120
  26. data/lib/card/cache/persistent.rb +50 -0
  27. data/lib/card/cache/temporary.rb +38 -0
  28. data/lib/card/chunk.rb +34 -25
  29. data/lib/card/content.rb +3 -3
  30. data/lib/card/env.rb +3 -0
  31. data/lib/card/format.rb +56 -53
  32. data/lib/card/migration.rb +6 -2
  33. data/lib/card/name.rb +9 -1
  34. data/lib/card/query.rb +1 -1
  35. data/lib/card/reference.rb +17 -11
  36. data/lib/card/set.rb +1 -1
  37. data/lib/card/subcards.rb +6 -6
  38. data/lib/card/view_cache.rb +45 -28
  39. data/lib/generators/card/migration/templates/card_migration.erb +1 -2
  40. data/mod/01_core/chunk/include.rb +71 -48
  41. data/mod/01_core/chunk/link.rb +6 -3
  42. data/mod/01_core/chunk/query_reference.rb +38 -29
  43. data/mod/01_core/chunk/reference.rb +23 -24
  44. data/mod/01_core/set/all/collection.rb +1 -1
  45. data/mod/01_core/set/all/fetch.rb +39 -12
  46. data/mod/01_core/set/all/permissions.rb +2 -4
  47. data/mod/01_core/set/all/references.rb +50 -75
  48. data/mod/01_core/set/all/rules.rb +19 -18
  49. data/mod/01_core/set/all/subcards.rb +1 -1
  50. data/mod/01_core/set/all/templating.rb +31 -88
  51. data/mod/01_core/set/all/tracked_attributes.rb +7 -14
  52. data/mod/01_core/set/all/utils.rb +77 -66
  53. data/mod/01_core/set_pattern/07_type_plus_right.rb +6 -3
  54. data/mod/01_core/spec/set/all/fetch_spec.rb +148 -96
  55. data/mod/01_core/spec/set/all/templating_spec.rb +49 -40
  56. data/mod/01_core/spec/set/all/trash_spec.rb +1 -1
  57. data/mod/01_history/set/all/actions.rb +1 -1
  58. data/mod/02_basic_types/set/all/base.rb +13 -7
  59. data/mod/02_basic_types/set/all/rss.rb +17 -22
  60. data/mod/02_basic_types/set/type/plain_text.rb +5 -2
  61. data/mod/02_basic_types/spec/set/all/base_spec.rb +1 -0
  62. data/mod/02_basic_types/spec/set/all/rss_spec.rb +7 -6
  63. data/mod/03_machines/lib/javascript/wagn.js.coffee +22 -9
  64. data/mod/03_machines/set/right/machine_output.rb +1 -1
  65. data/mod/04_settings/lib/card/setting.rb +45 -31
  66. data/mod/04_settings/set/right/structure.rb +47 -1
  67. data/mod/04_settings/set/self/default_html_view.rb +2 -0
  68. data/mod/04_settings/set/self/follow_fields.rb +2 -0
  69. data/mod/04_settings/set/self/recent_settings.rb +1 -1
  70. data/mod/05_standard/file/favicon/image-icon.png +0 -0
  71. data/mod/05_standard/file/favicon/image-large.png +0 -0
  72. data/mod/05_standard/file/favicon/image-medium.png +0 -0
  73. data/mod/05_standard/file/favicon/image-original.png +0 -0
  74. data/mod/05_standard/file/favicon/image-small.png +0 -0
  75. data/mod/05_standard/set/all/links.rb +27 -26
  76. data/mod/05_standard/set/all/rich_html/editing.rb +1 -1
  77. data/mod/05_standard/set/all/rich_html/toolbar.rb +1 -1
  78. data/mod/05_standard/set/rstar/rules.rb +20 -325
  79. data/mod/05_standard/set/rstar/rules_editor.rb +362 -0
  80. data/mod/05_standard/set/self/admin_info.rb +82 -0
  81. data/mod/05_standard/set/self/all.rb +16 -10
  82. data/mod/05_standard/set/self/head.rb +20 -19
  83. data/mod/05_standard/set/type/signup.rb +0 -1
  84. data/mod/05_standard/spec/set/all/account_spec.rb +44 -43
  85. data/mod/05_standard/spec/set/right/account_spec.rb +4 -2
  86. data/mod/05_standard/spec/set/type/search_type_spec.rb +8 -0
  87. data/mod/05_standard/spec/set/type/signup_spec.rb +24 -17
  88. data/mod/06_bootstrap/set/all/bootstrap/helper.rb +1 -1
  89. data/spec/lib/card/cache_spec.rb +64 -70
  90. data/spec/lib/card/content_spec.rb +236 -150
  91. data/spec/lib/card/reference_spec.rb +22 -38
  92. data/spec/lib/card/subcards_spec.rb +38 -0
  93. data/spec/lib/card/view_cache_spec.rb +8 -0
  94. data/spec/spec_helper.rb +1 -1
  95. data/tmpsets/set/mod001-01_core/all/collection.rb +77 -74
  96. data/tmpsets/set/mod001-01_core/all/content.rb +14 -16
  97. data/tmpsets/set/mod001-01_core/all/fetch.rb +137 -110
  98. data/tmpsets/set/mod001-01_core/all/name.rb +58 -40
  99. data/tmpsets/set/mod001-01_core/all/pattern.rb +12 -11
  100. data/tmpsets/set/mod001-01_core/all/permissions.rb +125 -117
  101. data/tmpsets/set/mod001-01_core/all/phases.rb +2 -1
  102. data/tmpsets/set/mod001-01_core/all/references.rb +52 -77
  103. data/tmpsets/set/mod001-01_core/all/rules.rb +47 -53
  104. data/tmpsets/set/mod001-01_core/all/templating.rb +31 -87
  105. data/tmpsets/set/mod001-01_core/all/tracked_attributes.rb +12 -21
  106. data/tmpsets/set/mod001-01_core/all/trash.rb +4 -1
  107. data/tmpsets/set/mod001-01_core/all/type.rb +23 -21
  108. data/tmpsets/set/mod001-01_core/all/utils.rb +80 -64
  109. data/tmpsets/set/mod002-01_history/all/actions.rb +20 -16
  110. data/tmpsets/set/mod002-01_history/all/history.rb +18 -13
  111. data/tmpsets/set/mod003-02_basic_types/all/base.rb +37 -10
  112. data/tmpsets/set/mod003-02_basic_types/all/rss.rb +17 -22
  113. data/tmpsets/set/mod003-02_basic_types/type/plain_text.rb +5 -2
  114. data/tmpsets/set/mod003-02_basic_types/type/pointer.rb +51 -39
  115. data/tmpsets/set/mod004-03_machines/right/machine_output.rb +10 -6
  116. data/tmpsets/set/mod005-04_settings/abstract/permission.rb +10 -5
  117. data/tmpsets/set/mod005-04_settings/right/structure.rb +47 -1
  118. data/tmpsets/set/mod005-04_settings/self/recent_settings.rb +1 -0
  119. data/tmpsets/set/mod005-04_settings/type/setting.rb +4 -1
  120. data/tmpsets/set/mod006-05_email/all/follow.rb +45 -54
  121. data/tmpsets/set/mod006-05_email/all/notify.rb +88 -73
  122. data/tmpsets/set/mod006-05_email/right/followers.rb +17 -14
  123. data/tmpsets/set/mod006-05_email/self/follow_defaults.rb +22 -18
  124. data/tmpsets/set/mod006-05_email/type/email_template.rb +1 -1
  125. data/tmpsets/set/mod007-05_standard/abstract/attachment.rb +94 -67
  126. data/tmpsets/set/mod007-05_standard/all/account.rb +18 -20
  127. data/tmpsets/set/mod007-05_standard/all/comment.rb +51 -29
  128. data/tmpsets/set/mod007-05_standard/all/error.rb +129 -99
  129. data/tmpsets/set/mod007-05_standard/all/links.rb +27 -26
  130. data/tmpsets/set/mod007-05_standard/all/rich_html/content.rb +115 -103
  131. data/tmpsets/set/mod007-05_standard/all/rich_html/editing.rb +112 -78
  132. data/tmpsets/set/mod007-05_standard/all/rich_html/form.rb +123 -81
  133. data/tmpsets/set/mod007-05_standard/all/rich_html/modal.rb +15 -58
  134. data/tmpsets/set/mod007-05_standard/all/rich_html/toolbar.rb +2 -2
  135. data/tmpsets/set/mod007-05_standard/right/account.rb +71 -75
  136. data/tmpsets/set/mod007-05_standard/right/email.rb +16 -13
  137. data/tmpsets/set/mod007-05_standard/right/password.rb +20 -12
  138. data/tmpsets/set/mod007-05_standard/right/status.rb +2 -2
  139. data/tmpsets/set/mod007-05_standard/right/token.rb +49 -2
  140. data/tmpsets/set/mod007-05_standard/rstar/rules.rb +20 -325
  141. data/tmpsets/set/mod007-05_standard/self/all.rb +16 -10
  142. data/tmpsets/set/mod007-05_standard/self/head.rb +76 -62
  143. data/tmpsets/set/mod007-05_standard/self/search.rb +45 -22
  144. data/tmpsets/set/mod007-05_standard/self/signin.rb +14 -12
  145. data/tmpsets/set/mod007-05_standard/type/cardtype.rb +13 -11
  146. data/tmpsets/set/mod007-05_standard/type/file.rb +1 -1
  147. data/tmpsets/set/mod007-05_standard/type/search_type.rb +3 -2
  148. data/tmpsets/set/mod007-05_standard/type/set.rb +20 -16
  149. data/tmpsets/set/mod007-05_standard/type/signup.rb +19 -25
  150. data/tmpsets/set/mod007-05_standard/type/user.rb +1 -1
  151. data/tmpsets/set/mod008-06_bootstrap/all/bootstrap/helper.rb +1 -1
  152. data/tmpsets/set_pattern/106-type_plus_right.rb +6 -3
  153. metadata +11 -2
@@ -146,7 +146,8 @@ def phase_ok? opts
146
146
  phase && (
147
147
  (opts[:during] && in?(opts[:during])) ||
148
148
  (opts[:before] && before?(opts[:before])) ||
149
- (opts[:after] && after?(opts[:after]))
149
+ (opts[:after] && after?(opts[:after])) ||
150
+ true # no phase restriction in opts
150
151
  )
151
152
  end
152
153
 
@@ -2,118 +2,94 @@
2
2
  class Card; module Set; module All; module References; extend Card::Set
3
3
  # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/references.rb ~~~~~~~~~~~
4
4
 
5
+ PARTIAL_REF_CODE = 'P'
6
+
5
7
  def name_referencers link_name=nil
6
8
  link_name = link_name.nil? ? key : link_name.to_name.key
7
- Card.joins( :references_to ).where card_references: { referee_key: link_name }
9
+ Card.joins(:references_to).where card_references: { referee_key: link_name }
8
10
  end
9
11
 
10
12
  def extended_referencers
11
- # FIXME .. we really just need a number here.
12
- (dependents + [self]).map(&:referencers).flatten.uniq
13
+ # FIXME: .. we really just need a number here.
14
+ (descendants + [self]).map(&:referencers).flatten.uniq
13
15
  end
14
16
 
15
-
16
17
  # replace references in card content
17
18
  def replace_references old_name, new_name
18
- obj_content = Card::Content.new raw_content, card=self
19
- obj_content.find_chunks( Card::Chunk::Reference ).select do |chunk|
20
- if old_ref_name = chunk.referee_name and new_ref_name = old_ref_name.replace_part(old_name, new_name)
21
- chunk.referee_name = chunk.replace_reference old_name, new_name
22
- Card::Reference.where( referee_key: old_ref_name.key ).update_all referee_key: new_ref_name.key
23
- end
19
+ obj_content = Card::Content.new raw_content, self
20
+ obj_content.find_chunks(Card::Chunk::Reference).select do |chunk|
21
+ next unless (old_ref_name = chunk.referee_name)
22
+ next unless (new_ref_name = old_ref_name.replace_part old_name, new_name)
23
+ chunk.referee_name = chunk.replace_reference old_name, new_name
24
+ old_references = Card::Reference.where(referee_key: old_ref_name.key)
25
+ old_references.update_all referee_key: new_ref_name.key
24
26
  end
25
27
 
26
28
  obj_content.to_s
27
29
  end
28
30
 
29
31
  # update entries in reference table
30
- def update_references rendered_content = nil, refresh = false
31
- raise "update references should not be called on new cards" if id.nil?
32
-
33
- Card::Reference.delete_all_from self
32
+ def update_references rendered_content=nil
33
+ raise 'update references should not be called on new cards' if id.nil?
34
34
 
35
- # FIXME: why not like this: references_expired = nil # do we have to make sure this is saved?
36
- #Card.update( id, references_expired: nil )
37
- # or just this and save it elsewhere?
38
- #references_expired=nil
35
+ Card::Reference.delete_all_from self unless self.new_card?
39
36
 
40
- Card.connection.execute("update cards set references_expired=NULL where id=#{id}")
41
- # references_expired = nil
42
- expire if refresh
43
-
44
- rendered_content ||= Card::Content.new(raw_content, card=self)
37
+ rendered_content ||= Card::Content.new raw_content, self
45
38
  rendered_content.find_chunks(Card::Chunk::Reference).each do |chunk|
46
- if referee_name = chunk.referee_name # name is referenced (not true of commented inclusions)
47
- referee_id = chunk.referee_id
48
- if id != referee_id # not self reference
49
-
50
- #update_references chunk.referee_name if Card::Content === chunk.referee_name
51
- # for the above to work we will need to get past delete_all!
52
- referee_name.piece_names.each do |name|
53
- if name.key != key # don't create self reference
54
-
55
- # reference types:
56
- # L = link
57
- # I = inclusion
58
- # P = partial (i.e. the name is part of a compound name that is referenced by a link or inclusion)
59
-
60
- # The partial type is needed to keep track of references of virtual cards.
61
- # For example a link [[A+*self]] won't make it to the reference table because A+*self is virtual and
62
- # doesn't have an id but when A's name is changed we have to find and update that link.
63
- ref_type =
64
- if name == referee_name
65
- case chunk
66
- when Card::Chunk::Link then 'L'
67
- when Card::Chunk::QueryReference then 'Q'
68
- else 'I'
69
- end
70
- else 'P'
71
- end
72
- Card::Reference.create!(
73
- referer_id: id,
74
- referee_id: Card.where(key: name.key).pluck(:id).first,
75
- referee_key: name.key,
76
- ref_type: ref_type,
77
- present: 1
78
- )
79
- end
80
- end
81
- end
82
-
83
- end
39
+ create_reference_to chunk
84
40
  end
85
41
  end
86
42
 
87
-
43
+ def create_reference_to chunk
44
+ referee_name = chunk.referee_name
45
+ return false unless referee_name # eg no commented nest
46
+
47
+ referee_name.piece_names.each do |name|
48
+ next if name.key == key # don't create self reference
49
+
50
+ # reference types:
51
+ # L = link
52
+ # I = inclusion
53
+ # P = partial (i.e. the name is part of a compound name that is
54
+ # referenced by a link or inclusion)
55
+
56
+ # The partial type is needed to keep track of references of virtual cards.
57
+ # For example a link [[A+*self]] won't make it to the reference table
58
+ # because A+*self is virtual and doesn't have an id but when A's name is
59
+ # changed we have to find and update that link.
60
+ ref_type = name != referee_name ? PARTIAL_REF_CODE : chunk.reference_code
61
+ Card::Reference.create!(
62
+ referer_id: id,
63
+ referee_id: Card.fetch_id(name),
64
+ referee_key: name.key,
65
+ ref_type: ref_type,
66
+ present: 1
67
+ )
68
+ end
69
+ end
88
70
 
89
71
  def referencers
90
- return [] unless refs = references_from
91
- refs.map(&:referer_id).map( &Card.method(:fetch) ).compact
72
+ references_from.map(&:referer_id).map(&Card.method(:fetch)).compact
92
73
  end
93
74
 
94
75
  def includers
95
- return [] unless refs = references_from.where( ref_type: 'I' )
96
- refs.map(&:referer_id).map( &Card.method(:fetch) ).compact
76
+ references_from.where(ref_type: 'I')
77
+ .map(&:referer_id).map(&Card.method(:fetch)).compact
97
78
  end
98
79
 
99
80
  def referees
100
- return [] unless refs = references_to
101
- refs.map { |ref| Card.fetch ref.referee_key, new: {} }.compact
81
+ references_to.map { |ref| Card.fetch ref.referee_key, new: {} }
102
82
  end
103
83
 
104
84
  def includees
105
- return [] unless refs = references_to.where( ref_type: 'I' )
106
- refs.map { |ref| Card.fetch ref.referee_key, new: {} }.compact
85
+ references_to.where(ref_type: 'I')
86
+ .map { |ref| Card.fetch ref.referee_key, new: {} }
107
87
  end
108
88
 
109
-
110
-
111
89
  protected
112
90
 
113
-
114
- event :refresh_references, after: :store, on: :save do
115
- self.update_references
116
- expire_structuree_references
91
+ event :refresh_references, after: :store, on: :save, changed: :content do
92
+ update_references
117
93
  end
118
94
 
119
95
  event :refresh_references_on_create, before: :refresh_references, on: :create do
@@ -123,7 +99,6 @@ end
123
99
 
124
100
  event :refresh_references_on_delete, after: :store, on: :delete do
125
101
  Card::Reference.update_on_delete self
126
- expire_structuree_references
127
102
  end
128
103
 
129
104
 
@@ -1,10 +1,9 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  class Card; module Set; module All; module Rules; extend Card::Set
3
3
  # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/rules.rb ~~~~~~~~~~~
4
-
5
-
6
4
  RuleSQL = %{
7
- select rules.id as rule_id, settings.id as setting_id, sets.id as set_id, sets.left_id as anchor_id, sets.right_id as set_tag_id
5
+ select rules.id as rule_id, settings.id as setting_id, sets.id as set_id,
6
+ sets.left_id as anchor_id, sets.right_id as set_tag_id
8
7
  from cards rules
9
8
  join cards sets on rules.left_id = sets.id
10
9
  join cards settings on rules.right_id = settings.id
@@ -22,15 +21,15 @@ ReadRuleSQL = %{
22
21
  where read_rules.right_id = #{Card::ReadID} and read_rules.trash is false and sets.type_id = #{Card::SetID};
23
22
  }
24
23
 
25
- def is_rule?
26
- is_standard_rule? || is_user_rule?
27
- end
24
+ def is_rule?
25
+ is_standard_rule? || is_user_rule?
26
+ end
28
27
 
29
28
  def is_standard_rule?
30
- (r = right( skip_modules: true )) &&
31
- r.type_id == Card::SettingID &&
32
- (l = left( skip_modules: true )) &&
33
- l.type_id == Card::SetID
29
+ (r = right( skip_modules: true )) &&
30
+ r.type_id == Card::SettingID &&
31
+ (l = left( skip_modules: true )) &&
32
+ l.type_id == Card::SetID
34
33
  end
35
34
 
36
35
  def is_user_rule?
@@ -51,7 +50,7 @@ def rule setting_code, options={}
51
50
  end
52
51
 
53
52
  def rule_card setting_code, options={}
54
- Card.fetch rule_card_id( setting_code, options ), options
53
+ Card.fetch rule_card_id(setting_code, options), options
55
54
  end
56
55
 
57
56
  def rule_card_id setting_code, options={}
@@ -74,21 +73,24 @@ def rule_card_id setting_code, options={}
74
73
  end
75
74
 
76
75
  def related_sets with_self = false
77
- # refers to sets that users may configure from the current card - NOT to sets to which the current card belongs
76
+ # refers to sets that users may configure from the current card -
77
+ # NOT to sets to which the current card belongs
78
78
 
79
- sets = []
80
- sets << ["#{name}+*type", Card::TypeSet.label( name) ] if known? && type_id==Card::CardtypeID
81
- sets << ["#{name}+*self", Card::SelfSet.label( name) ] if with_self
82
- sets << ["#{name}+*right", Card::RightSet.label(name) ] if known? && cardname.simple?
79
+ # FIXME: change to use codenames!!
83
80
 
84
- # Card.search(type: 'Set',left: {right: name},right: '*type plus right',return: 'name').each do |set_name|
85
- # sets<< set_name
86
- # end
81
+ sets = []
82
+ if known? && type_id == Card::CardtypeID # FIXME: belongs in type/cardtype
83
+ sets << ["#{name}+*type", Card::TypeSet.label(name)]
84
+ end
85
+ if with_self
86
+ sets << ["#{name}+*self", Card::SelfSet.label(name)]
87
+ end
88
+ if known? && cardname.simple?
89
+ sets << ["#{name}+*right", Card::RightSet.label(name)]
90
+ end
87
91
  sets
88
92
  end
89
93
 
90
-
91
-
92
94
  module ClassMethods
93
95
 
94
96
  # User-specific rule use the pattern
@@ -113,18 +115,20 @@ module ClassMethods
113
115
  join cards settings on user_rules.right_id = settings.id
114
116
  join cards users on user_sets.right_id = users.id
115
117
  join cards sets on user_sets.left_id = sets.id
116
- where sets.type_id = #{Card::SetID } and sets.trash is false
117
- and settings.type_id = #{Card::SettingID} and settings.trash is false
118
- and ( #{user_restriction} or users.codename = 'all' ) and users.trash is false
119
- and user_sets.trash is false
120
- and user_rules.trash is false;
118
+ where sets.type_id = #{Card::SetID }
119
+ and settings.type_id = #{Card::SettingID}
120
+ and (#{user_restriction} or users.codename = 'all')
121
+ and sets.trash is false
122
+ and settings.trash is false
123
+ and users.trash is false
124
+ and user_sets.trash is false
125
+ and user_rules.trash is false;
121
126
  }
122
127
  end
123
128
 
124
-
125
- def setting name
129
+ def global_setting name
126
130
  Auth.as_bot do
127
- card=Card[name] and !card.db_content.strip.empty? and card.db_content
131
+ (card = Card[name]) && !card.db_content.strip.empty? && card.db_content
128
132
  end
129
133
  end
130
134
 
@@ -177,11 +181,12 @@ module ClassMethods
177
181
  end
178
182
 
179
183
  def all_user_ids_with_rule_for set_card, setting_code
180
- key = if (l=set_card.left) and (r=set_card.right)
181
- set_class_code = Codename[ r.id ]
184
+ key =
185
+ if (l = set_card.left) && (r = set_card.right)
186
+ set_class_code = Codename[r.id]
182
187
  "#{l.id}+#{set_class_code}+#{setting_code}"
183
188
  else
184
- set_class_code = Codename[ set_card.id ]
189
+ set_class_code = Codename[set_card.id]
185
190
  "#{set_class_code}+#{setting_code}"
186
191
  end
187
192
  user_ids = user_ids_cache[key] || []
@@ -190,11 +195,14 @@ module ClassMethods
190
195
  else
191
196
  user_ids
192
197
  end
193
-
194
198
  end
195
199
 
196
200
  def user_rule_cards user_name, setting_code
197
- Card.search right: {codename: setting_code}, left: {left: {type_id: SetID}, right: user_name}
201
+ Card.search(
202
+ { right: { codename: setting_code },
203
+ left: { left: { type_id: SetID }, right: user_name }
204
+ }, "rule cards for user: #{user_name}"
205
+ )
198
206
  end
199
207
 
200
208
  def rule_cache
@@ -285,15 +293,15 @@ module ClassMethods
285
293
  Card.cache.write 'RULE_KEYS', hash
286
294
  end
287
295
 
288
-
289
-
290
296
  def read_rule_cache
291
297
  Card.cache.read('READRULES') || begin
292
298
  hash = {}
293
- ActiveRecord::Base.connection.select_all( Card::Set::All::Rules::ReadRuleSQL ).each do |row|
294
- party_id, read_rule_id = row['party_id'].to_i, row['read_rule_id'].to_i
299
+ ActiveRecord::Base.connection.select_all(
300
+ Card::Set::All::Rules::ReadRuleSQL
301
+ ).each do |row|
302
+ party_id = row['party_id'].to_i
295
303
  hash[party_id] ||= []
296
- hash[party_id] << read_rule_id
304
+ hash[party_id] << row['read_rule_id'].to_i
297
305
  end
298
306
  Card.cache.write 'READRULES', hash
299
307
  end
@@ -302,22 +310,8 @@ module ClassMethods
302
310
  def clear_read_rule_cache
303
311
  Card.cache.write 'READRULES', nil
304
312
  end
305
- =begin
306
- def default_rule setting_code, fallback=nil
307
- card = default_rule_card setting_code, fallback
308
- return card && card.content
309
- end
310
-
311
- def default_rule_card setting_code, fallback=nil
312
- rule_id = rule_cache["all+#{setting_code}"]
313
- rule_id ||= fallback && rule_cache["all+#{fallback}"]
314
- Card[rule_id] if rule_id
315
- end
316
- =end
317
313
  end
318
314
 
319
315
 
320
-
321
-
322
316
  # ~~~~~~~~~~~ below autogenerated; above pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/rules.rb ~~~~~~~~~~~
323
317
  end;end;end;end;
@@ -16,117 +16,61 @@ def template
16
16
  @template ||= begin
17
17
  @virtual = false
18
18
 
19
- # NEW CARDS
20
19
  if new_card?
21
- default = rule_card :default, skip_modules: true
22
-
23
- dup_card = dup
24
- dup_card.type_id = default ? default.type_id : Card.default_type_id
25
-
26
- if structure = dup_card.structure_rule_card
27
- @virtual = true if junction?
28
- self.type_id = structure.type_id if assign_type_to?(structure)
29
- structure
30
- else
31
- default
32
- end
33
-
34
- # EXISTING CARDS
35
- elsif structure = structure_rule_card
36
- repair_type structure.type_id if assign_type_to?(structure)
37
- structure
20
+ new_card_template
21
+ else
22
+ structure_rule_card
38
23
  end
39
24
  end
40
25
  end
41
26
 
42
- def assign_type_to? structure
43
- type_id != structure.type_id and structure.assigns_type?
44
- end
45
-
46
- def structure
47
- if template && template.is_structure?
48
- template
49
- end
50
- end
51
-
52
- def virtual?
53
- return false unless new_card?
54
- if @virtual.nil?
55
- cardname.simple? ? @virtual=false : template
56
- end
57
- @virtual
58
- end
27
+ def new_card_template
28
+ default = rule_card :default, skip_modules: true
59
29
 
60
- def structure_rule_card
61
- card = rule_card :structure, skip_modules: true
62
- card && card.db_content.strip == '_self' ? nil : card
63
- end
30
+ dup_card = dup
31
+ dup_card.type_id = default ? default.type_id : Card.default_type_id
64
32
 
65
- def structuree_names
66
- if wql = structuree_spec
67
- Auth.as_bot do
68
- Card::Query.run(wql.merge return: :name)
69
- end
33
+ if (structure = dup_card.structure_rule_card)
34
+ @virtual = true if junction?
35
+ self.type_id = structure.type_id if assign_type_to?(structure)
36
+ structure
70
37
  else
71
- []
38
+ default
72
39
  end
73
40
  end
74
41
 
75
- # FIXME: content settings -- do we really need the reference expiration system?
76
- #
77
- # I kind of think so. otherwise how do we handled patterned references in hard-templated cards?
78
- # I'll leave the FIXME here until the need (and/or other solution) is well documented. -efm
79
-
80
- def expire_structuree_references
81
- update_structurees references_expired: 1
82
- end
83
-
84
- def update_structurees args
85
- # note that this is not smart about overriding templating rules
86
- # for example, if someone were to change the type of a +*right+*structure rule that was overridden
87
- # by a +*type plus right+*structure rule, the override would not be respected.
88
- if query = structuree_spec
89
- Auth.as_bot do
90
- query[:return] = :id
91
- Card::Query.run(query).each_slice(100) do |id_batch|
92
- Card.where( id: id_batch ).update_all args
93
- end
94
- end
95
- end
42
+ def assign_type_to? structure
43
+ return if type_id == structure.type_id
44
+ structure.assigns_type?
96
45
  end
97
46
 
98
47
  def assigns_type?
99
48
  # needed because not all *structure templates govern the type of set members
100
49
  # for example, X+*type+*structure governs all cards of type X,
101
50
  # but the content rule does not (in fact cannot) have the type X.
102
- if is_structure?
103
- if set_pattern = Card.fetch( cardname.trunk_name.tag_name, skip_modules: true )
104
- pattern_code = set_pattern.codename and
105
- set_class = Card::SetPattern.find( pattern_code ) and
106
- set_class.assigns_type
107
- end
108
- end
51
+ return unless (set_pattern = Card.fetch cardname.trunk_name.tag_name,
52
+ skip_modules: true)
53
+ return unless (pattern_code = set_pattern.codename)
54
+ return unless (set_class = Card::SetPattern.find pattern_code)
55
+ set_class.assigns_type
109
56
  end
110
57
 
111
- private
112
-
113
- def repair_type template_type_id
114
- # this is a mechanism for repairing bad data. like #repair_key, it should be obviated and removed.
115
- self.type_id = template_type_id
116
- update_column :type_id, type_id
117
- reset_patterns
58
+ def structure
59
+ return unless template && template.is_structure?
60
+ template
118
61
  end
119
62
 
120
- def structuree_spec
121
- if is_structure? and c=trunk and c.type_id = Card::SetID #could use is_rule?...
122
- c.get_query
63
+ def virtual?
64
+ return false unless new_card?
65
+ if @virtual.nil?
66
+ cardname.simple? ? (@virtual = false) : template
123
67
  end
68
+ @virtual
124
69
  end
125
70
 
126
- event :update_structurees_type, after: :store, changed: :type_id do
127
- if assigns_type? # certain *structure templates
128
- update_structurees type_id: type_id
129
- end
71
+ def structure_rule_card
72
+ card = rule_card :structure, skip_modules: true
73
+ card && card.db_content.strip == '_self' ? nil : card
130
74
  end
131
75
 
132
76