card 1.16.9 → 1.16.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/db/migrate_core_cards/20120611203506_rails_inflection_updates.rb +3 -1
  4. data/db/seed/new/card_actions.yml +389 -557
  5. data/db/seed/new/card_acts.yml +595 -1
  6. data/db/seed/new/card_changes.yml +22595 -7526
  7. data/db/seed/new/card_references.yml +379 -407
  8. data/db/seed/new/cards.yml +1694 -2072
  9. data/db/seed/test/fixtures/card_actions.yml +966 -1102
  10. data/db/seed/test/fixtures/card_acts.yml +1017 -399
  11. data/db/seed/test/fixtures/card_changes.yml +24750 -9681
  12. data/db/seed/test/fixtures/card_references.yml +603 -631
  13. data/db/seed/test/fixtures/cards.yml +2293 -2671
  14. data/lib/card/set.rb +1 -1
  15. data/mod/01_core/set/all/content.rb +14 -12
  16. data/mod/03_machines/lib/javascript/wagn_mod.js.coffee +1 -1
  17. data/mod/05_standard/set/abstract/attachment.rb +9 -9
  18. data/mod/05_standard/set/all/rich_html/content.rb +115 -103
  19. data/mod/05_standard/set/type/file.rb +1 -1
  20. data/tmpsets/set/mod001-01_core/all/active_card.rb +2 -1
  21. data/tmpsets/set/mod001-01_core/all/collection.rb +3 -3
  22. data/tmpsets/set/mod001-01_core/all/content.rb +2 -1
  23. data/tmpsets/set/mod001-01_core/all/erb.rb +2 -1
  24. data/tmpsets/set/mod001-01_core/all/fetch.rb +169 -93
  25. data/tmpsets/set/mod001-01_core/all/haml.rb +2 -1
  26. data/tmpsets/set/mod001-01_core/all/initialize.rb +11 -23
  27. data/tmpsets/set/mod001-01_core/all/name.rb +130 -80
  28. data/tmpsets/set/mod001-01_core/all/pattern.rb +2 -1
  29. data/tmpsets/set/mod001-01_core/all/permissions.rb +2 -1
  30. data/tmpsets/set/mod001-01_core/all/phases.rb +95 -96
  31. data/tmpsets/set/mod001-01_core/all/references.rb +2 -1
  32. data/tmpsets/set/mod001-01_core/all/rules.rb +2 -1
  33. data/tmpsets/set/mod001-01_core/all/states.rb +2 -1
  34. data/tmpsets/set/mod001-01_core/all/templating.rb +2 -1
  35. data/tmpsets/set/mod001-01_core/all/tracked_attributes.rb +85 -60
  36. data/tmpsets/set/mod001-01_core/all/trash.rb +16 -13
  37. data/tmpsets/set/mod001-01_core/all/type.rb +5 -25
  38. data/tmpsets/set/mod001-01_core/all/utils.rb +2 -1
  39. data/tmpsets/set/mod001-01_core/all/view_cache.rb +2 -1
  40. data/tmpsets/set/mod002-01_history/all/actions.rb +2 -1
  41. data/tmpsets/set/mod002-01_history/all/content_history.rb +7 -4
  42. data/tmpsets/set/mod002-01_history/all/history.rb +119 -83
  43. data/tmpsets/set/mod003-02_basic_types/all/all_css.rb +2 -1
  44. data/tmpsets/set/mod003-02_basic_types/all/all_csv.rb +2 -1
  45. data/tmpsets/set/mod003-02_basic_types/all/all_js.rb +2 -1
  46. data/tmpsets/set/mod003-02_basic_types/all/base.rb +52 -50
  47. data/tmpsets/set/mod003-02_basic_types/all/file.rb +2 -1
  48. data/tmpsets/set/mod003-02_basic_types/all/json.rb +2 -1
  49. data/tmpsets/set/mod003-02_basic_types/all/rss.rb +2 -1
  50. data/tmpsets/set/mod003-02_basic_types/all/text.rb +2 -1
  51. data/tmpsets/set/mod003-02_basic_types/type/html.rb +2 -1
  52. data/tmpsets/set/mod003-02_basic_types/type/plain_text.rb +2 -1
  53. data/tmpsets/set/mod003-02_basic_types/type/pointer.rb +10 -1
  54. data/tmpsets/set/mod004-03_machines/right/machine_input.rb +2 -1
  55. data/tmpsets/set/mod004-03_machines/right/machine_output.rb +2 -1
  56. data/tmpsets/set/mod004-03_machines/self/script_ace.rb +2 -1
  57. data/tmpsets/set/mod004-03_machines/self/script_card_menu.rb +2 -1
  58. data/tmpsets/set/mod004-03_machines/self/script_html5shiv_printshiv.rb +2 -1
  59. data/tmpsets/set/mod004-03_machines/self/script_jquery.rb +2 -1
  60. data/tmpsets/set/mod004-03_machines/self/script_jquery_helper.rb +2 -1
  61. data/tmpsets/set/mod004-03_machines/self/script_slot.rb +2 -1
  62. data/tmpsets/set/mod004-03_machines/self/script_tinymce.rb +2 -1
  63. data/tmpsets/set/mod004-03_machines/self/style_bootstrap_compatible.rb +2 -1
  64. data/tmpsets/set/mod004-03_machines/self/style_cards.rb +2 -1
  65. data/tmpsets/set/mod004-03_machines/self/style_jquery_ui_smoothness.rb +2 -1
  66. data/tmpsets/set/mod004-03_machines/type/coffee_script.rb +2 -1
  67. data/tmpsets/set/mod004-03_machines/type/css.rb +2 -1
  68. data/tmpsets/set/mod004-03_machines/type/java_script.rb +2 -1
  69. data/tmpsets/set/mod004-03_machines/type/scss.rb +2 -1
  70. data/tmpsets/set/mod004-03_machines/type/skin.rb +2 -1
  71. data/tmpsets/set/mod005-04_settings/abstract/permission.rb +2 -1
  72. data/tmpsets/set/mod005-04_settings/right/add_help.rb +2 -1
  73. data/tmpsets/set/mod005-04_settings/right/comment.rb +2 -1
  74. data/tmpsets/set/mod005-04_settings/right/create.rb +2 -1
  75. data/tmpsets/set/mod005-04_settings/right/default.rb +2 -1
  76. data/tmpsets/set/mod005-04_settings/right/delete.rb +2 -1
  77. data/tmpsets/set/mod005-04_settings/right/help.rb +2 -1
  78. data/tmpsets/set/mod005-04_settings/right/read.rb +2 -1
  79. data/tmpsets/set/mod005-04_settings/right/script.rb +2 -1
  80. data/tmpsets/set/mod005-04_settings/right/structure.rb +2 -1
  81. data/tmpsets/set/mod005-04_settings/right/style.rb +2 -1
  82. data/tmpsets/set/mod005-04_settings/right/update.rb +2 -1
  83. data/tmpsets/set/mod005-04_settings/self/accountable.rb +2 -1
  84. data/tmpsets/set/mod005-04_settings/self/add_help.rb +2 -1
  85. data/tmpsets/set/mod005-04_settings/self/autoname.rb +2 -1
  86. data/tmpsets/set/mod005-04_settings/self/captcha.rb +2 -1
  87. data/tmpsets/set/mod005-04_settings/self/create.rb +2 -1
  88. data/tmpsets/set/mod005-04_settings/self/default.rb +2 -1
  89. data/tmpsets/set/mod005-04_settings/self/delete.rb +2 -1
  90. data/tmpsets/set/mod005-04_settings/self/help.rb +2 -1
  91. data/tmpsets/set/mod005-04_settings/self/input.rb +2 -1
  92. data/tmpsets/set/mod005-04_settings/self/layout.rb +2 -1
  93. data/tmpsets/set/mod005-04_settings/self/on_create.rb +2 -1
  94. data/tmpsets/set/mod005-04_settings/self/on_delete.rb +2 -1
  95. data/tmpsets/set/mod005-04_settings/self/on_update.rb +2 -1
  96. data/tmpsets/set/mod005-04_settings/self/options.rb +2 -1
  97. data/tmpsets/set/mod005-04_settings/self/options_label.rb +2 -1
  98. data/tmpsets/set/mod005-04_settings/self/read.rb +2 -1
  99. data/tmpsets/set/mod005-04_settings/self/recent_settings.rb +2 -1
  100. data/tmpsets/set/mod005-04_settings/self/script.rb +2 -1
  101. data/tmpsets/set/mod005-04_settings/self/structure.rb +2 -1
  102. data/tmpsets/set/mod005-04_settings/self/style.rb +2 -1
  103. data/tmpsets/set/mod005-04_settings/self/table_of_contents.rb +2 -1
  104. data/tmpsets/set/mod005-04_settings/self/thanks.rb +2 -1
  105. data/tmpsets/set/mod005-04_settings/self/update.rb +2 -1
  106. data/tmpsets/set/mod005-04_settings/type/setting.rb +2 -1
  107. data/tmpsets/set/mod006-05_email/all/email_html.rb +2 -1
  108. data/tmpsets/set/mod006-05_email/all/email_text.rb +2 -1
  109. data/tmpsets/set/mod006-05_email/all/follow.rb +2 -1
  110. data/tmpsets/set/mod006-05_email/all/notify.rb +2 -1
  111. data/tmpsets/set/mod006-05_email/all/observer.rb +2 -1
  112. data/tmpsets/set/mod006-05_email/right/bcc.rb +2 -1
  113. data/tmpsets/set/mod006-05_email/right/cc.rb +2 -1
  114. data/tmpsets/set/mod006-05_email/right/follow.rb +2 -1
  115. data/tmpsets/set/mod006-05_email/right/follow_fields.rb +2 -1
  116. data/tmpsets/set/mod006-05_email/right/followers.rb +7 -6
  117. data/tmpsets/set/mod006-05_email/right/following.rb +3 -2
  118. data/tmpsets/set/mod006-05_email/right/from.rb +2 -1
  119. data/tmpsets/set/mod006-05_email/right/html_message.rb +2 -1
  120. data/tmpsets/set/mod006-05_email/right/to.rb +2 -1
  121. data/tmpsets/set/mod006-05_email/self/always.rb +2 -1
  122. data/tmpsets/set/mod006-05_email/self/created.rb +2 -1
  123. data/tmpsets/set/mod006-05_email/self/edited.rb +2 -1
  124. data/tmpsets/set/mod006-05_email/self/follow.rb +2 -1
  125. data/tmpsets/set/mod006-05_email/self/follow_defaults.rb +2 -1
  126. data/tmpsets/set/mod006-05_email/self/never.rb +2 -1
  127. data/tmpsets/set/mod006-05_email/type/email_template.rb +2 -1
  128. data/tmpsets/set/mod006-05_email/type_plus_right/user/follow.rb +3 -2
  129. data/tmpsets/set/mod007-05_standard/abstract/attachment.rb +22 -9
  130. data/tmpsets/set/mod007-05_standard/all/account.rb +2 -1
  131. data/tmpsets/set/mod007-05_standard/all/comment.rb +2 -1
  132. data/tmpsets/set/mod007-05_standard/all/error.rb +2 -1
  133. data/tmpsets/set/mod007-05_standard/all/event_viz.rb +2 -1
  134. data/tmpsets/set/mod007-05_standard/all/links.rb +2 -1
  135. data/tmpsets/set/mod007-05_standard/all/rich_html/content.rb +3 -2
  136. data/tmpsets/set/mod007-05_standard/all/rich_html/editing.rb +2 -1
  137. data/tmpsets/set/mod007-05_standard/all/rich_html/form.rb +23 -12
  138. data/tmpsets/set/mod007-05_standard/all/rich_html/header.rb +2 -1
  139. data/tmpsets/set/mod007-05_standard/all/rich_html/menu.rb +3 -2
  140. data/tmpsets/set/mod007-05_standard/all/rich_html/modal.rb +2 -1
  141. data/tmpsets/set/mod007-05_standard/all/rich_html/toolbar.rb +2 -1
  142. data/tmpsets/set/mod007-05_standard/all/rich_html/wrapper.rb +2 -1
  143. data/tmpsets/set/mod007-05_standard/right/account.rb +7 -6
  144. data/tmpsets/set/mod007-05_standard/right/discussion.rb +2 -1
  145. data/tmpsets/set/mod007-05_standard/right/email.rb +2 -1
  146. data/tmpsets/set/mod007-05_standard/right/password.rb +2 -1
  147. data/tmpsets/set/mod007-05_standard/right/salt.rb +2 -1
  148. data/tmpsets/set/mod007-05_standard/right/stats.rb +2 -1
  149. data/tmpsets/set/mod007-05_standard/right/status.rb +2 -1
  150. data/tmpsets/set/mod007-05_standard/right/token.rb +2 -1
  151. data/tmpsets/set/mod007-05_standard/right/when_created.rb +2 -1
  152. data/tmpsets/set/mod007-05_standard/right/when_last_edited.rb +2 -1
  153. data/tmpsets/set/mod007-05_standard/rstar/rules.rb +2 -1
  154. data/tmpsets/set/mod007-05_standard/self/account_links.rb +2 -1
  155. data/tmpsets/set/mod007-05_standard/self/alerts.rb +2 -1
  156. data/tmpsets/set/mod007-05_standard/self/all.rb +2 -1
  157. data/tmpsets/set/mod007-05_standard/self/foot.rb +2 -1
  158. data/tmpsets/set/mod007-05_standard/self/head.rb +2 -2
  159. data/tmpsets/set/mod007-05_standard/self/navbox.rb +2 -1
  160. data/tmpsets/set/mod007-05_standard/self/now.rb +2 -1
  161. data/tmpsets/set/mod007-05_standard/self/recent.rb +2 -1
  162. data/tmpsets/set/mod007-05_standard/self/search.rb +2 -1
  163. data/tmpsets/set/mod007-05_standard/self/signin.rb +45 -36
  164. data/tmpsets/set/mod007-05_standard/self/stats.rb +2 -1
  165. data/tmpsets/set/mod007-05_standard/self/version.rb +2 -1
  166. data/tmpsets/set/mod007-05_standard/type/basic.rb +2 -1
  167. data/tmpsets/set/mod007-05_standard/type/cardtype.rb +2 -1
  168. data/tmpsets/set/mod007-05_standard/type/date.rb +2 -1
  169. data/tmpsets/set/mod007-05_standard/type/file.rb +11 -3
  170. data/tmpsets/set/mod007-05_standard/type/image.rb +2 -1
  171. data/tmpsets/set/mod007-05_standard/type/layout_type.rb +2 -1
  172. data/tmpsets/set/mod007-05_standard/type/number.rb +2 -1
  173. data/tmpsets/set/mod007-05_standard/type/phrase.rb +2 -1
  174. data/tmpsets/set/mod007-05_standard/type/search_type.rb +70 -64
  175. data/tmpsets/set/mod007-05_standard/type/session.rb +2 -1
  176. data/tmpsets/set/mod007-05_standard/type/set.rb +2 -1
  177. data/tmpsets/set/mod007-05_standard/type/signup.rb +96 -64
  178. data/tmpsets/set/mod007-05_standard/type/toggle.rb +2 -1
  179. data/tmpsets/set/mod007-05_standard/type/uri.rb +2 -1
  180. data/tmpsets/set/mod007-05_standard/type/user.rb +50 -40
  181. data/tmpsets/set/mod008-06_bootstrap/all/bootstrap/form.rb +2 -1
  182. data/tmpsets/set/mod008-06_bootstrap/all/bootstrap/helper.rb +2 -1
  183. data/tmpsets/set/mod008-06_bootstrap/all/bootstrap/wrapper.rb +2 -1
  184. data/tmpsets/set/mod008-06_bootstrap/all/rich_bootstrap.rb +2 -1
  185. data/tmpsets/set/mod008-06_bootstrap/self/bootstrap_cards.rb +2 -1
  186. data/tmpsets/set/mod008-06_bootstrap/self/bootstrap_js.rb +2 -1
  187. data/tmpsets/set/mod008-06_bootstrap/self/bootswatch_shared.rb +2 -1
  188. data/tmpsets/set/mod008-06_bootstrap/self/smartmenu_css.rb +2 -1
  189. data/tmpsets/set/mod008-06_bootstrap/self/smartmenu_js.rb +2 -1
  190. metadata +2 -2
@@ -1,26 +1,46 @@
1
1
  # -*- encoding : utf-8 -*-
2
- class Card; module Set; module All; module Name; extend Card::Set # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/name.rb ~~~~~~~~~~~
2
+ class Card; module Set; module All; module Name; extend Card::Set
3
+ # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/name.rb ~~~~~~~~~~~
3
4
  require 'uuid'
4
5
 
6
+ module ClassMethods
7
+ def uniquify_name name, rename=false
8
+ return name unless Card[name]
9
+ uniq_name = "#{name} 1"
10
+ while Card[uniq_name]
11
+ uniq_name.next!
12
+ end
13
+ return uniq_name unless rename
14
+
15
+ Card[name].update_attributes! name: uniq_name,
16
+ update_referencers: true
17
+ # name conflict resolved; original name can be used
18
+ name
19
+ end
20
+ end
21
+
5
22
  def name= newname
6
23
  cardname = newname.to_name
7
24
  if @supercard
8
- @relative_name = cardname.to_s
9
- relparts = @relative_name.to_name.parts
10
- @superleft = @supercard if relparts.size==2 && relparts.first.blank?
11
- cardname = @relative_name.to_name.to_absolute_name @supercard.name
25
+ @supercard.subcards.rename key, cardname.key
26
+ @contextual_name = cardname.to_s
27
+ relparts = cardname.parts
28
+ if relparts.size == 2 &&
29
+ (relparts.first.blank? || relparts.first.to_name.key == @supercard.key)
30
+ @superleft = @supercard
31
+ end
32
+ cardname = cardname.to_absolute_name @supercard.name
12
33
  end
13
34
 
14
35
  newkey = cardname.key
15
36
  if key != newkey
16
37
  self.key = newkey
17
- reset_patterns_if_rule # reset the old name - should be handled in tracked_attributes!!
38
+ # reset the old name - should be handled in tracked_attributes!!
39
+ reset_patterns_if_rule
18
40
  reset_patterns
19
41
  end
20
-
21
- subcards.each do |subkey, subcard|
22
- next unless Card===subcard
23
- subcard.name = subkey.to_name.to_absolute cardname
42
+ subcards.each do |subcard|
43
+ subcard.name = subcard.cardname.replace_part name, newname
24
44
  end
25
45
 
26
46
  write_attribute :name, cardname.s
@@ -47,49 +67,63 @@ def junction?
47
67
  cardname.junction?
48
68
  end
49
69
 
70
+ def contextual_name
71
+ @contextual_name || name
72
+ end
73
+
74
+ def relative_name context_name=nil
75
+ if !context_name && @supercard
76
+ context_name = @supercard.cardname
77
+ end
78
+ cardname.relative_name(context_name)
79
+ end
50
80
 
51
- def relative_name
52
- @relative_name || name
81
+ def absolute_name context_name=nil
82
+ if !context_name && @supercard
83
+ context_name = @supercard.cardname
84
+ end
85
+ cardname.absolute_name(context_name)
53
86
  end
54
87
 
55
88
  def left *args
56
- if !simple?
57
- @superleft or begin
58
- unless name_changed? and name.to_name.trunk_name.key == name_was.to_name.key
59
- # prevent recursion when, eg, renaming A+B to A+B+C
60
- Card.fetch cardname.left, *args
61
- end
89
+ return if simple?
90
+ @superleft || begin
91
+ unless name_changed? &&
92
+ name.to_name.trunk_name.key == name_was.to_name.key
93
+ # prevent recursion when, eg, renaming A+B to A+B+C
94
+ Card.fetch cardname.left, *args
62
95
  end
63
96
  end
64
97
  end
65
98
 
66
99
  def right *args
67
- Card.fetch( cardname.right, *args ) if !simple?
100
+ Card.fetch(cardname.right, *args) if !simple?
68
101
  end
69
102
 
70
103
  def [] *args
71
- if args[0].kind_of?(Fixnum) || args[0].kind_of?(Range)
104
+ case args[0]
105
+ when Fixnum, Range
72
106
  fetch_name = Array.wrap(cardname.parts[args[0]]).compact.join '+'
73
- Card.fetch( fetch_name, args[1] || {} ) if !simple?
107
+ Card.fetch(fetch_name, args[1] || {}) if !simple?
74
108
  else
75
109
  super
76
110
  end
77
111
  end
78
112
 
79
113
  def trunk *args
80
- simple? ? self : left( *args )
114
+ simple? ? self : left(*args)
81
115
  end
82
116
 
83
117
  def tag *args
84
- simple? ? self : Card.fetch( cardname.right, *args )
118
+ simple? ? self : Card.fetch(cardname.right, *args)
85
119
  end
86
120
 
87
121
  def left_or_new args={}
88
- left args or Card.new args.merge(name: cardname.left)
122
+ left(args) || Card.new(args.merge(name: cardname.left))
89
123
  end
90
124
 
91
125
  def children
92
- Card.search( { (simple? ? :part : :left) => name } ).to_a
126
+ Card.search((simple? ? :part : :left) => name).to_a
93
127
  end
94
128
 
95
129
  def dependents
@@ -103,7 +137,7 @@ def dependents
103
137
  array + card.dependents
104
138
  end
105
139
  end
106
- #Rails.logger.warn "dependents[#{inspect}] #{@dependents.inspect}"
140
+ # Rails.logger.warn "dependents[#{inspect}] #{@dependents.inspect}"
107
141
  end
108
142
  @dependents
109
143
  end
@@ -112,18 +146,18 @@ def repair_key
112
146
  Auth.as_bot do
113
147
  correct_key = cardname.key
114
148
  current_key = key
115
- return self if current_key==correct_key
149
+ return self if current_key == correct_key
116
150
 
117
- if key_blocker = Card.find_by_key_and_trash(correct_key, true)
151
+ if (key_blocker = Card.find_by_key_and_trash(correct_key, true))
118
152
  key_blocker.cardname = key_blocker.cardname + "*trash#{rand(4)}"
119
153
  key_blocker.save
120
154
  end
121
155
 
122
- saved = ( self.key = correct_key and self.save! )
123
- saved ||= ( self.cardname = current_key and self.save! )
156
+ saved = (self.key = correct_key) && self.save!
157
+ saved ||= (self.cardname = current_key) && self.save!
124
158
 
125
159
  if saved
126
- self.dependents.each { |c| c.repair_key }
160
+ dependents.each(&:repair_key)
127
161
  else
128
162
  Rails.logger.debug "FAILED TO REPAIR BROKEN KEY: #{key}"
129
163
  self.name = "BROKEN KEY: #{name}"
@@ -135,13 +169,13 @@ rescue
135
169
  self
136
170
  end
137
171
 
138
-
139
172
  event :permit_codename, before: :approve, on: :update, changed: :codename do
140
173
  errors.add :codename, 'only admins can set codename' unless Auth.always_ok?
141
174
  end
142
175
 
143
176
  event :validate_unique_codename, after: :permit_codename do
144
- if codename.present? and errors.empty? and Card.find_by_codename(codename).present?
177
+ if codename.present? && errors.empty? &&
178
+ Card.find_by_codename(codename).present?
145
179
  errors.add :codename, "codename #{codename} already in use"
146
180
  end
147
181
  end
@@ -149,45 +183,46 @@ end
149
183
  event :validate_name, before: :approve, on: :save do
150
184
  cdname = name.to_name
151
185
  if name.length > 255
152
- errors.add :name, "is too long (255 character maximum)"
186
+ errors.add :name, 'is too long (255 character maximum)'
153
187
  elsif cdname.blank?
154
188
  errors.add :name, "can't be blank"
155
189
  elsif name_changed?
156
- #Rails.logger.debug "valid name #{card.name.inspect} New #{name.inspect}"
190
+ # Rails.logger.debug "valid name #{card.name.inspect} New #{name.inspect}"
157
191
 
158
192
  unless cdname.valid?
159
- errors.add :name, "may not contain any of the following characters: #{ Card::Name.banned_array * ' ' }"
193
+ errors.add :name, 'may not contain any of the following characters: ' \
194
+ "#{ Card::Name.banned_array * ' ' }"
160
195
  end
161
196
  # this is to protect against using a plus card as a tag
162
- if cdname.junction? and simple? and id and Auth.as_bot { Card.count_by_wql right_id: id } > 0
197
+ if cdname.junction? && simple? && id &&
198
+ Auth.as_bot { Card.count_by_wql right_id: id } > 0
163
199
  errors.add :name, "#{name} in use as a tag"
164
200
  end
165
201
 
166
202
  # validate uniqueness of name
167
- condition_sql = "cards.key = ? and trash=?"
168
- condition_params = [ cdname.key, false ]
203
+ condition_sql = 'cards.key = ? and trash=?'
204
+ condition_params = [cdname.key, false]
169
205
  unless new_record?
170
- condition_sql << " AND cards.id <> ?"
206
+ condition_sql << ' AND cards.id <> ?'
171
207
  condition_params << id
172
208
  end
173
- if c = Card.find_by(condition_sql, *condition_params)
209
+ if (c = Card.find_by(condition_sql, *condition_params))
174
210
  errors.add :name, "must be unique; '#{c.name}' already exists."
175
211
  end
176
212
  end
177
213
  end
178
214
 
179
-
180
215
  event :set_autoname, before: :validate_name, on: :create do
181
- if name.blank? and autoname_card = rule_card(:autoname)
216
+ if name.blank? && (autoname_card = rule_card(:autoname))
182
217
  self.name = autoname autoname_card.content
183
- Auth.as_bot { autoname_card.refresh.update_attributes! content: name } #fixme, should give placeholder on new, do next and save on create
218
+ # FIXME: should give placeholder on new, do next and save on create
219
+ Auth.as_bot { autoname_card.refresh.update_attributes! content: name }
184
220
  end
185
221
  end
186
222
 
187
-
188
223
  event :validate_key, after: :validate_name, on: :save do
189
224
  if key.empty?
190
- errors.add :key, "cannot be blank" if errors.empty?
225
+ errors.add :key, 'cannot be blank' if errors.empty?
191
226
  elsif key != cardname.key
192
227
  errors.add :key, "wrong key '#{key}' for name #{name}"
193
228
  end
@@ -199,9 +234,12 @@ event :set_name, before: :store, changed: :name do
199
234
  if cardname.junction?
200
235
  [:left, :right].each do |side|
201
236
  sidename = cardname.send "#{side}_name"
202
- #warn "sidename #{name} / #{name_was} / #{cardname}, #{side}: #{sidename}"
237
+ # warn "sidename #{name} / #{name_was} / #{cardname},
238
+ # #{side}: #{sidename}"
203
239
  sidecard = Card[sidename]
204
- old_name_in_way = (sidecard && sidecard.id==self.id) # eg, renaming A to A+B
240
+
241
+ # eg, renaming A to A+B
242
+ old_name_in_way = (sidecard && sidecard.id == id)
205
243
  suspend_name(sidename) if old_name_in_way
206
244
  send "#{side}_id=", begin
207
245
  if !sidecard || old_name_in_way
@@ -216,60 +254,72 @@ event :set_name, before: :store, changed: :name do
216
254
  end
217
255
  end
218
256
 
219
-
220
257
  event :rename, after: :set_name, on: :update do
221
- if existing_card = Card.find_by_key_and_trash(cardname.key, true) and existing_card != self
222
- existing_card.name = existing_card.name+'*trash'
258
+ if (existing_card = Card.find_by_key_and_trash(cardname.key, true)) &&
259
+ existing_card != self
260
+ existing_card.name = existing_card.name + '*trash'
223
261
  existing_card.rename_without_callbacks
224
262
  existing_card.save!
225
263
  end
226
264
  end
227
265
 
228
- def suspend_name(name)
266
+ def suspend_name name
229
267
  # move the current card out of the way, in case the new name will require
230
268
  # re-creating a card with the current name, ie. A -> A+B
231
269
  Card.expire name
232
- tmp_name = "tmp:" + UUID.new.generate
233
- Card.where(id: self.id).update_all(name: tmp_name, key: tmp_name)
270
+ tmp_name = 'tmp:' + UUID.new.generate
271
+ Card.where(id: id).update_all(name: tmp_name, key: tmp_name)
234
272
  end
235
273
 
236
-
237
274
  event :cascade_name_changes, after: :store, on: :update, changed: :name do
238
- #Rails.logger.info "------------------- #{name_was} CASCADE #{self.name} -------------------------------------"
239
-
240
- self.update_referencers = false if self.update_referencers == 'false' #handle strings from cgi
275
+ # Rails.logger.info "------------------- #{name_was} CASCADE #{self.name} " \
276
+ # " -------------------------------------"
277
+ # handle strings from cgi
278
+ self.update_referencers = false if update_referencers == 'false'
241
279
  Card::Reference.update_on_rename self, name, self.update_referencers
242
280
 
243
- deps = self.dependents
244
- #warn "-------------------#{name_was}---- CASCADE #{self.name} -> deps: #{deps.map(&:name)*", "} -----------------------"
281
+ deps = dependents
282
+ # warn "-------------------#{name_was}---- CASCADE #{self.name} -> deps: " \
283
+ # " #{deps.map(&:name)*', '} -----------------------"
245
284
 
246
- @dependents = nil #reset
285
+ @dependents = nil # reset
247
286
 
248
287
  deps.each do |dep|
249
- # here we specifically want NOT to invoke recursive cascades on these cards, have to go this low level to avoid callbacks.
288
+ # here we specifically want NOT to invoke recursive cascades on these
289
+ # cards, have to go this low level to avoid callbacks.
250
290
  Rails.logger.info "cascading name: #{dep.name}"
251
- Card.expire dep.name #old name
291
+ Card.expire dep.name # old name
252
292
  newname = dep.cardname.replace_part name_was, name
253
- Card.where( id: dep.id ).update_all name: newname.to_s, key: newname.key
293
+ Card.where(id: dep.id).update_all name: newname.to_s, key: newname.key
254
294
  Card::Reference.update_on_rename dep, newname, update_referencers
255
295
  Card.expire newname
256
296
  end
257
- if update_referencers
258
- Auth.as_bot do
259
- [self.name_referencers(name_was)+(deps.map &:referencers)].flatten.uniq.each do |card|
260
- # FIXME using "name_referencers" instead of plain "referencers" for self because there are cases where trunk and tag
261
- # have already been saved via association by this point and therefore referencers misses things
262
- # eg. X includes Y, and Y is renamed to X+Z. When X+Z is saved, X is first updated as a trunk before X+Z gets to this point.
263
- # so at this time X is still including Y, which does not exist. therefore #referencers doesn't find it, but name_referencers(old_name) does.
264
- # some even more complicated scenario probably breaks on the dependents, so this probably needs a more thoughtful refactor
265
- # aligning the dependent saving with the name cascading
266
-
267
- Rails.logger.debug "------------------ UPDATE REFERER #{card.name} ------------------------"
268
- unless card == self or card.structure
269
- card = card.refresh
270
- card.db_content = card.replace_references name_was, name
271
- card.save!
272
- end
297
+ execute_referencers_update(deps) if update_referencers
298
+ end
299
+
300
+ def execute_referencers_update dependents
301
+ Auth.as_bot do
302
+ [name_referencers(name_was) + dependents.map(&:referencers)]
303
+ .flatten.uniq.each do |card|
304
+ # FIXME: using 'name_referencers' instead of plain 'referencers' for self
305
+ # because there are cases where trunk and tag
306
+ # have already been saved via association by this point and therefore
307
+ # referencers misses things
308
+ # eg. X includes Y, and Y is renamed to X+Z. When X+Z is saved, X is
309
+ # first updated as a trunk before X+Z gets to this point.
310
+ # so at this time X is still including Y, which does not exist.
311
+ # therefore #referencers doesn't find it, but name_referencers(old_name)
312
+ # does.
313
+ # some even more complicated scenario probably breaks on the dependents,
314
+ # so this probably needs a more thoughtful refactor
315
+ # aligning the dependent saving with the name cascading
316
+
317
+ Rails.logger.debug "------------------ UPDATE REFERER #{card.name} " \
318
+ '------------------------'
319
+ unless card == self || card.structure
320
+ card = card.refresh
321
+ card.db_content = card.replace_references name_was, name
322
+ card.save!
273
323
  end
274
324
  end
275
325
  end
@@ -1,5 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
- class Card; module Set; module All; module Pattern; extend Card::Set # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/pattern.rb ~~~~~~~~~~~
2
+ class Card; module Set; module All; module Pattern; extend Card::Set
3
+ # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/pattern.rb ~~~~~~~~~~~
3
4
 
4
5
  def patterns
5
6
  @patterns ||= set_patterns.map { |sub| sub.new(self) }.compact
@@ -1,5 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
- class Card; module Set; module All; module Permissions; extend Card::Set # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/permissions.rb ~~~~~~~~~~~
2
+ class Card; module Set; module All; module Permissions; extend Card::Set
3
+ # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/permissions.rb ~~~~~~~~~~~
3
4
 
4
5
  Card.error_codes.merge! permission_denied: [:denial, 403], captcha: [:errors,449]
5
6
 
@@ -1,33 +1,35 @@
1
1
  # -*- encoding : utf-8 -*-
2
- class Card; module Set; module All; module Phases; extend Card::Set # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/phases.rb ~~~~~~~~~~~
2
+ class Card; module Set; module All; module Phases; extend Card::Set
3
+ # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/phases.rb ~~~~~~~~~~~
3
4
 
4
- # The Card#abort method is for cleanly exiting an action without continuing to process any further events.
5
+ # The Card#abort method is for cleanly exiting an action without continuing
6
+ # to process any further events.
5
7
  #
6
8
  # Three statuses are supported:
7
9
  #
8
10
  # failure: adds an error, returns false on save
9
11
  # success: no error, returns true on save
10
- # triumph: similar to success, but if called on a subcard it causes the entire action to abort (not just the subcard)
12
+ # triumph: similar to success, but if called on a subcard
13
+ # it causes the entire action to abort (not just the subcard)
11
14
 
12
- def abort status, msg='action canceled'
15
+ def abort status, msg = 'action canceled'
13
16
  if status == :failure && errors.empty?
14
17
  errors.add :abort, msg
15
- elsif Hash === status and status[:success]
18
+ elsif Hash === status && status[:success]
16
19
  success << status[:success]
17
20
  status = :success
18
21
  end
19
- raise Card::Abort.new( status, msg)
22
+ raise Card::Abort.new(status, msg)
20
23
  end
21
24
 
22
-
23
25
  def abortable
24
26
  yield
25
27
  rescue Card::Abort => e
26
28
  if e.status == :triumph
27
- @supercard ? raise( e ) : true
29
+ @supercard ? raise(e) : true
28
30
  elsif e.status == :success
29
31
  if @supercard
30
- @supercard.subcards.delete_if { |k,v| v==self }
32
+ @supercard.subcards.delete(key)
31
33
  end
32
34
  true
33
35
  end
@@ -37,7 +39,8 @@ def valid_subcard?
37
39
  abortable { valid? }
38
40
  end
39
41
 
40
- # this is an override of standard rails behavior that rescues abortmakes it so that :success abortions do not rollback
42
+ # this is an override of standard rails behavior that rescues abort
43
+ # makes it so that :success abortions do not rollback
41
44
  def with_transaction_returning_status
42
45
  status = nil
43
46
  self.class.transaction do
@@ -49,78 +52,122 @@ def with_transaction_returning_status
49
52
  end
50
53
 
51
54
  # perhaps above should be in separate module?
52
- #~~~~~~
55
+ # ~~~~~~
56
+
57
+ PHASES = {}
58
+ [:prepare, :approve, :store, :stored, :extend, :subsequent]
59
+ .each_with_index do |phase, i|
60
+ PHASES[phase] = i
61
+ end
62
+
63
+ def run_phase phase, &block
64
+ @phase = phase
65
+ @subphase = :before
66
+ if block_given?
67
+ block.call
68
+ else
69
+ run_callbacks phase
70
+ end
71
+ @subphase = :after
72
+ end
73
+
74
+ def simulate_phase opts, &block
75
+ @phase
76
+ end
77
+
78
+ def phase
79
+ @phase || (@supercard && @supercard.phase)
80
+ end
81
+
82
+ def subphase
83
+ @subphase || (@supercard && @supercard.subphase)
84
+ end
53
85
 
54
86
  def prepare
55
87
  @action = identify_action
56
88
  # the following should really happen when type, name etc are changed
57
89
  reset_patterns
58
90
  include_set_modules
59
- run_callbacks :prepare
60
- rescue =>e
91
+ run_phase :prepare
92
+ rescue => e
61
93
  rescue_event e
62
94
  end
63
95
 
64
96
  def approve
65
97
  @action ||= identify_action
66
- run_callbacks :approve
98
+ run_phase :approve
67
99
  expire_pieces if errors.any?
68
100
  errors.empty?
69
- rescue =>e
101
+ rescue => e
70
102
  rescue_event e
71
103
  end
72
104
 
73
105
  def identify_action
74
106
  case
75
- when trash ; :delete
76
- when new_card? ; :create
77
- else :update
107
+ when trash then :delete
108
+ when new_card? then :create
109
+ else :update
78
110
  end
79
111
  end
80
112
 
81
-
82
113
  def store
83
- run_callbacks :store do
84
- yield #unless @draft
85
- @virtual = false
114
+ run_phase :store do
115
+ run_callbacks :store do
116
+ yield # unless @draft
117
+ @virtual = false
118
+ end
86
119
  end
87
- run_callbacks :stored
88
- rescue =>e
120
+ run_phase :stored
121
+ rescue => e
89
122
  rescue_event e
90
123
  ensure
91
- @from_trash = @last_action_id = @last_content_action_id = nil
124
+ @from_trash = @last_content_action_id = nil
92
125
  end
93
126
 
94
-
95
127
  def extend
96
-
97
- run_callbacks :extend
98
- run_callbacks :subsequent
99
- rescue =>e
128
+ run_phase :extend
129
+ run_phase :subsequent
130
+ rescue => e
100
131
  rescue_event e
101
132
  ensure
102
133
  @action = nil
103
134
  end
104
135
 
105
-
106
-
107
-
108
136
  def rescue_event e
109
137
  @action = nil
110
138
  expire_pieces
111
- subcards.each do |key, card|
112
- next unless Card===card
113
- card.expire_pieces
114
- end
139
+ subcards.each(&:expire_pieces)
115
140
  raise e
116
- #rescue Card::Cancel
117
- # false
141
+ # rescue Card::Cancel
142
+ # false
118
143
  end
119
144
 
120
- event :notable_exception_raised do
121
- Rails.logger.debug "BT: #{Card::Error.current.backtrace*"\n "}"
145
+ def phase_ok? opts
146
+ phase && (
147
+ (opts[:during] && in?(opts[:during])) ||
148
+ (opts[:before] && before?(opts[:before])) ||
149
+ (opts[:after] && after?(opts[:after]))
150
+ )
151
+ end
152
+
153
+ def before? allowed_phase
154
+ PHASES[allowed_phase] > PHASES[phase] ||
155
+ (PHASES[allowed_phase] == PHASES[phase] && subphase == :before)
122
156
  end
123
157
 
158
+ def after? allowed_phase
159
+ PHASES[allowed_phase] < PHASES[phase] ||
160
+ (PHASES[allowed_phase] == PHASES[phase] && subphase == :after)
161
+ end
162
+
163
+ def in? allowed_phase
164
+ (allowed_phase.is_a?(Array) && allowed_phase.include?(phase)) ||
165
+ allowed_phase == phase
166
+ end
167
+
168
+ event :notable_exception_raised do
169
+ Rails.logger.debug "BT: #{Card::Error.current.backtrace * "\n "}"
170
+ end
124
171
 
125
172
  def event_applies? opts
126
173
  on_condition_applies?(opts[:on]) &&
@@ -138,8 +185,13 @@ end
138
185
 
139
186
  def changed_condition_applies? db_column
140
187
  if db_column
141
- db_column = 'db_content' if db_column.to_sym == :content
142
- @action != :delete && changes[db_column.to_s]
188
+ db_column =
189
+ case db_column.to_sym
190
+ when :content then 'db_content'
191
+ when :type then 'type_id'
192
+ else db_column.to_s
193
+ end
194
+ @action != :delete && changes[db_column]
143
195
  else
144
196
  true
145
197
  end
@@ -153,63 +205,10 @@ def when_condition_applies? block
153
205
  end
154
206
  end
155
207
 
156
-
157
- def subcards
158
- @subcards ||= {}
159
- end
160
-
161
-
162
- event :process_subcards, after: :approve, on: :save do
163
- subcards.keys.each do |sub_name|
164
- opts = @subcards[sub_name] || {}
165
- opts = { 'content' => opts } if String===opts
166
- ab_name = sub_name.to_name.to_absolute_name name
167
- next if ab_name.key == key # don't resave self!
168
-
169
- opts = opts.stringify_keys
170
- opts['subcards'] = extract_subcard_args! opts
171
-
172
- opts[:supercard] = self
173
-
174
- subcard =
175
- if known_card = Card[ab_name]
176
- known_card.refresh.assign_attributes opts
177
- known_card
178
- elsif (opts['content'].present? && opts['content'].strip.present?) ||
179
- opts['subcards'].present? || opts['file'].present? || opts['image'].present?
180
- Card.new opts.reverse_merge 'name' => sub_name
181
- end
182
-
183
- if subcard
184
- @subcards[sub_name] = subcard
185
- else
186
- @subcards.delete sub_name
187
- end
188
- end
189
- end
190
-
191
- event :approve_subcards, after: :process_subcards do
192
- subcards.each do |key, subcard|
193
- if !subcard.valid_subcard?
194
- subcard.errors.each do |field, err|
195
- err = "#{field} #{err}" unless [:content, :abort].member? field
196
- errors.add subcard.relative_name, err
197
- end
198
- end
199
- end
200
- end
201
-
202
- event :store_subcards, after: :store do
203
- subcards.each do |key, sub|
204
- sub.save! validate: false #unless @draft
205
- end
206
- end
207
-
208
208
  def success
209
209
  Env.success(cardname)
210
210
  end
211
211
 
212
212
 
213
-
214
213
  # ~~~~~~~~~~~ below autogenerated; above pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/phases.rb ~~~~~~~~~~~
215
214
  end;end;end;end;