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
@@ -24,7 +24,7 @@ def assign_attributes args={}
24
24
  end
25
25
 
26
26
  def assign_set_specific_attributes
27
- return unless @set_specific && @set_specific.present?
27
+ return unless @set_specific.present?
28
28
  @set_specific.each_pair do |name, value|
29
29
  send "#{name}=", value
30
30
  end
@@ -68,7 +68,7 @@ event :set_content, before: :store, on: :save do
68
68
  self.db_content = Card::Content.clean!(db_content) if clean_html?
69
69
  @selected_action_id = @selected_content = nil
70
70
  clear_drafts
71
- reset_patterns_if_rule saving=true
71
+ reset_patterns_if_rule true
72
72
  end
73
73
 
74
74
  # FIXME: the following don't really belong here, but they have to come after
@@ -104,11 +104,6 @@ event :update_ruled_cards, after: :store do
104
104
  item_card.update_read_rule
105
105
  end
106
106
  end
107
- # elsif rule_class_index = rule_class_ids.index( 0 )
108
- # in_set[trunk.key] = true
109
- # #warn "self rule update: #{trunk.inspect}, #{rule_class_index},
110
- # #{cur_index}"
111
- # trunk.update_read_rule if cur_index > rule_class_index
112
107
  else warn "No current rule index #{class_id}, " \
113
108
  "#{rule_class_ids.inspect}"
114
109
  end
@@ -119,10 +114,10 @@ event :update_ruled_cards, after: :store do
119
114
 
120
115
  # then find all cards with me as read_rule_id that were not just updated
121
116
  # and regenerate their read_rules
122
- if !new_record?
123
- Card.where(read_rule_id: self.id, trash: false).reject do |w|
124
- in_set[w.key]
125
- end.each(&:update_read_rule)
117
+ if !new_card?
118
+ Card.search(read_rule_id: self.id) do |card|
119
+ card.update_read_rule unless in_set[card.key]
120
+ end
126
121
  end
127
122
  end
128
123
  end
@@ -133,27 +128,23 @@ event :process_read_rule_update_queue, after: :store do
133
128
  @read_rule_update_queue = []
134
129
  end
135
130
 
136
- # set_callback :store, :after, :process_read_rule_update_queue, prepend: true
137
-
138
131
  event :expire_related, after: :store do
139
132
  subcards.keys.each do |key|
140
- Card.cache.delete_local key
133
+ Card.cache.soft.delete key
141
134
  end
142
135
  expire true
143
136
 
144
- if self.is_structure?
137
+ if is_structure?
145
138
  structuree_names.each do |name|
146
139
  Card.expire name, true
147
140
  end
148
141
  end
142
+ end
149
143
 
150
- # FIXME: really shouldn't be instantiating all the following bastards.
151
- # Just need the key.
152
- # fix in id_cache branch
153
- dependents.each { |c| c.expire(true) }
154
- # self.referencers.each { |c| c.expire(true) }
144
+ event :expire_related_names, before: :expire_related, changed: :name do
145
+ # FIXME: look for opportunities to avoid instantiating the following
146
+ descendants.each { |c| c.expire(true) }
155
147
  name_referencers.each { |c| c.expire(true) }
156
- # FIXME: this will need review when we do the new defaults/templating system
157
148
  end
158
149
 
159
150
 
@@ -31,7 +31,10 @@ event :validate_delete, before: :approve, on: :delete do
31
31
  errors.add :delete, "#{name} is is a system card. (#{codename})"
32
32
  end
33
33
 
34
- undeletable_all_rules_tags = %w{ default style layout create read update delete }
34
+ undeletable_all_rules_tags =
35
+ %w{ default style layout create read update delete }
36
+ # FIXME: HACK! should be configured in the rule
37
+
35
38
  if junction? && (l = left) && l.codename == 'all' &&
36
39
  undeletable_all_rules_tags.member?(right.codename)
37
40
  errors.add :delete, "#{name} is an indestructible rule"
@@ -4,23 +4,27 @@ class Card; module Set; module All; module Type; extend Card::Set
4
4
 
5
5
  module ClassMethods
6
6
  def default_type_id
7
- @@default_type_id ||= Card[:all].fetch( trait: :default ).type_id
7
+ @@default_type_id ||= Card[:all].fetch(trait: :default).type_id
8
8
  end
9
9
  end
10
10
 
11
11
  def type_card
12
12
  return if type_id.nil?
13
- Card.fetch type_id.to_i, skip_modules: true
13
+ Card.quick_fetch type_id.to_i
14
14
  end
15
15
 
16
16
  def type_code
17
- Card::Codename[ type_id.to_i ]
17
+ Card::Codename[type_id.to_i]
18
18
  end
19
19
 
20
20
  def type_name
21
21
  type_card.try :name
22
22
  end
23
23
 
24
+ def type_name_or_default
25
+ type_card.try(:name) || Card.quick_fetch(Card.default_type_id).name
26
+ end
27
+
24
28
  def type_cardname
25
29
  type_card.try :cardname
26
30
  end
@@ -30,42 +34,40 @@ def type= type_name
30
34
  end
31
35
 
32
36
  def get_type_id_from_structure
33
- if name && (t = template)
34
- reset_patterns # still necessary even with new template handling?
35
- t.type_id
36
- end
37
+ return unless name && (t = template)
38
+ reset_patterns # still necessary even with new template handling?
39
+ t.type_id
37
40
  end
38
41
 
39
42
  event :validate_type_change, before: :approve, on: :update, changed: :type_id do
40
- if c = dup and c.action == :create and !c.valid?
41
- errors.add :type, "of #{ name } can't be changed; errors creating new #{ type_id }: #{ c.errors.full_messages * ', ' }"
43
+ if (c = dup) && c.action == :create && !c.valid?
44
+ errors.add :type, "of #{ name } can't be changed; errors creating new " \
45
+ "#{ type_id }: #{ c.errors.full_messages * ', ' }"
42
46
  end
43
47
  end
44
48
 
45
49
  event :validate_type, before: :approve, changed: :type_id do
46
50
  if !type_name
47
- errors.add :type, "No such type"
51
+ errors.add :type, 'No such type'
48
52
  end
49
53
 
50
- if rt = structure and rt.assigns_type? and type_id!=rt.type_id
51
- errors.add :type, "can't be changed because #{name} is hard templated to #{rt.type_name}"
54
+ if (rt = structure) && rt.assigns_type? && type_id != rt.type_id
55
+ errors.add :type, "can't be changed because #{name} is hard templated " \
56
+ "to #{rt.type_name}"
52
57
  end
53
58
  end
54
59
 
55
60
  event :reset_type_specific_fields, after: :store do
61
+ wql = { left: { left_id: type_id },
62
+ right: { codename: 'type_plus_right' }
63
+ }
64
+ wql_comment = "sets with a type_plus_right rule for #{name}"
65
+
56
66
  Auth.as_bot do
57
- Card.search left: { left_id: type_id }, right: {codename: 'type_plus_right'} do |set_card|
58
- set_card.reset_set_patterns
59
- end
67
+ Card.search(wql, wql_comment).each &:reset_set_patterns
60
68
  end
61
69
  end
62
70
 
63
- # Card.search left_plus: [ type_name, right_plus: {codename: 'type_plus_right'}] do |right_anchor|
64
- # Card["#{lef}"]
65
- # set_card.reset_set_patterns
66
- # end
67
-
68
-
69
71
 
70
72
  # ~~~~~~~~~~~ below autogenerated; above pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/type.rb ~~~~~~~~~~~
71
73
  end;end;end;end;
@@ -3,7 +3,6 @@ class Card; module Set; module All; module Utils; extend Card::Set
3
3
  # ~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/utils.rb ~~~~~~~~~~~
4
4
 
5
5
  module ClassMethods
6
-
7
6
  def empty_trash
8
7
  Card.delete_trashed_files
9
8
  Card.where(trash: true).delete_all
@@ -13,25 +12,39 @@ module ClassMethods
13
12
  Card.delete_tmp_files_of_cached_uploads
14
13
  end
15
14
 
16
- def delete_trashed_files #deletes any file not associated with a real card.
17
- dir = Card.paths['files'].existent.first
18
- trashed_card_sql = %{ select id from cards where trash is true }
19
- trashed_card_ids = Card.connection.select_all( trashed_card_sql ).map( &:values ).flatten.map &:to_i
20
- file_ids = Dir.entries( dir )[2..-1].map( &:to_i )
15
+ # deletes any file not associated with a real card.
16
+ def delete_trashed_files
17
+ trashed_card_ids = all_trashed_card_ids
18
+ file_ids = all_file_ids
21
19
  file_ids.each do |file_id|
22
20
  if trashed_card_ids.member?(file_id)
23
- raise Card::Error, "Narrowly averted deleting current file" if Card.exists?(file_id) #double check!
21
+ if Card.exists?(file_id) # double check!
22
+ fail Card::Error, 'Narrowly averted deleting current file'
23
+ end
24
24
  FileUtils.rm_rf "#{dir}/#{file_id}", secure: true
25
25
  end
26
26
  end
27
27
  end
28
28
 
29
+ def all_file_ids
30
+ dir = Card.paths['files'].existent.first
31
+ Dir.entries(dir)[2..-1].map(&:to_i)
32
+ end
33
+
34
+ def all_trashed_card_ids
35
+ trashed_card_sql = %{ select id from cards where trash is true }
36
+ sql_results = Card.connection.select_all(trashed_card_sql)
37
+ sql_results.map(&:values).flatten.map(&:to_i)
38
+ end
39
+
29
40
  def delete_tmp_files_of_cached_uploads
30
41
  actions = Card::Action.find_by_sql "SELECT * FROM card_actions
31
42
  INNER JOIN cards ON card_actions.card_id = cards.id
32
- WHERE cards.type_id IN (#{Card::FileID}, #{Card::ImageID}) AND card_actions.draft = true"
43
+ WHERE cards.type_id IN (#{Card::FileID}, #{Card::ImageID})
44
+ AND card_actions.draft = true"
33
45
  actions.each do |action|
34
- if older_than_five_days? action.created_at && card = action.card # we don't want to delete uploads in progress
46
+ if older_than_five_days?(action.created_at) && (card = action.card)
47
+ # we don't want to delete uploads in progress
35
48
  card.delete_files_for_action action
36
49
  end
37
50
  end
@@ -42,31 +55,31 @@ module ClassMethods
42
55
  attribs.each do |row|
43
56
  result = begin
44
57
  merge row['name'], row, opts
45
- # rescue => e
46
- # Rails.logger.info "merge_list problem: #{ e.message }"
47
- # false
48
58
  end
49
59
  unmerged.push row unless result == true
50
60
  end
51
61
 
52
62
  if unmerged.empty?
53
- Rails.logger.info "successfully merged all!"
63
+ Rails.logger.info 'successfully merged all!'
54
64
  else
55
65
  unmerged_json = JSON.pretty_generate unmerged
56
- if output_file = opts[:output_file]
57
- ::File.open output_file, 'w' do |f|
58
- f.write unmerged_json
59
- end
60
- else
61
- Rails.logger.info "failed to merge:\n\n#{ unmerged_json }"
62
- end
66
+ report_unmerged_json unmerged_json, opts[:output_file]
63
67
  end
64
68
  unmerged
65
69
  end
66
70
 
71
+ def report_unmerged_json unmerged_json, output_file
72
+ if output_file
73
+ ::File.open output_file, 'w' do |f|
74
+ f.write unmerged_json
75
+ end
76
+ else
77
+ Rails.logger.info "failed to merge:\n\n#{unmerged_json}"
78
+ end
79
+ end
67
80
 
68
81
  def merge name, attribs={}, opts={}
69
- puts "merging #{ name }"
82
+ puts "merging #{name}"
70
83
  card = fetch name, new: {}
71
84
 
72
85
  if opts[:pristine] && !card.pristine?
@@ -77,59 +90,60 @@ module ClassMethods
77
90
  end
78
91
  end
79
92
 
93
+ def older_than_five_days? time
94
+ Time.now - time > 432000
95
+ end
80
96
  end
81
97
 
82
98
  def debug_type
83
- "#{type_code||'no code'}:#{type_id}"
99
+ "#{type_code || 'no code'}:#{type_id}"
84
100
  end
85
101
 
86
102
  def to_s
87
- "#<#{self.class.name}[#{debug_type}]#{self.attributes['name']}>"
103
+ "#<#{self.class.name}[#{debug_type}]#{attributes['name']}>"
88
104
  end
89
105
 
90
106
  def inspect
91
- "#<#{self.class.name}" + "##{id}" +
92
- "###{object_id}" + #"l#{left_id}r#{right_id}" +
93
- "[#{debug_type}]" + "(#{self.name})" + #"#{object_id}" +
94
- #(errors.any? ? '*Errors*' : 'noE') +
95
- (errors.any? ? "<E*#{errors.full_messages*', '}*>" : '') +
96
- #"{#{references_expired==1 ? 'Exp' : "noEx"}:" +
97
- "{#{trash&&'trash:'||''}#{new_card? &&'new:'||''}#{frozen? ? 'Fz' : readonly? ? 'RdO' : ''}" +
98
- "#{@virtual &&'virtual:'||''}#{@set_mods_loaded&&'I'||'!loaded' }:#{references_expired.inspect}}" +
99
- '>'
107
+ tags = []
108
+ tags << 'trash' if trash
109
+ tags << 'new' if new_card?
110
+ tags << 'frozen' if frozen?
111
+ tags << 'readonly' if readonly?
112
+ tags << 'virtual' if @virtual
113
+ tags << 'set_mods_loaded' if @set_mods_loaded
114
+
115
+ error_messages = errors.any? ? "<E*#{errors.full_messages * ', '}*>" : ''
116
+
117
+ "#<Card##{id}[#{debug_type}](#{name})#{error_messages}{#{tags * ','}}"
100
118
  end
101
119
 
102
120
  format :html do
103
- view :views_by_format do |args|
104
- format_views = self.class.ancestors.each_with_object({}) do |format_class, hash|
105
- views =
106
- format_class.instance_methods.map do |method|
107
- if method.to_s.match /^_view_(.+)$/
108
- "<li>#{$1}</li>"
109
- end
110
- end.compact.join "\n"
111
- if views.present?
112
- format_class.name.match /^Card(::Set)?::(.+?)$/ #::(\w+Format)
113
- hash[$2] = views
121
+ view :views_by_format do
122
+ format_views =
123
+ self.class.ancestors.each_with_object({}) do |format_class, hash|
124
+ views =
125
+ format_class.instance_methods.map do |method|
126
+ if method.to_s.match(/^_view_(.+)$/)
127
+ "<li>#{$1}</li>"
128
+ end
129
+ end.compact.join "\n"
130
+ if views.present?
131
+ format_class.name.match(/^Card(::Set)?::(.+?)$/) #::(\w+Format)
132
+ hash[$2] = views
133
+ end
114
134
  end
115
- end
116
135
  accordion_group format_views
117
136
  end
118
137
 
119
- view :views_by_name do |args|
138
+ view :views_by_name do
120
139
  views = methods.map do |method|
121
- if method.to_s.match /^_view_(.+)$/
140
+ if method.to_s.match(/^_view_(.+)$/)
122
141
  $1
123
142
  end
124
143
  end.compact.sort
125
- "<ul>
126
- #{ wrap_each_with :li, views }
127
- </ul>"
144
+ "<ul>#{wrap_each_with :li, views}</ul>"
128
145
  end
129
146
 
130
-
131
-
132
-
133
147
  def accordion_group list, collapse_id=card.cardname.safe_key
134
148
  accordions = ''
135
149
  index = 1
@@ -137,31 +151,34 @@ format :html do
137
151
  accordions << accordion(title, content, "#{collapse_id}-#{index}")
138
152
  index += 1
139
153
  end
140
- content_tag :div, accordions.html_safe, class: "panel-group", id: "accordion-#{collapse_id}", role: "tablist", 'aria-multiselectable'=>"true"
154
+ content_tag :div, accordions.html_safe, class: 'panel-group',
155
+ id: "accordion-#{collapse_id}",
156
+ role: 'tablist',
157
+ 'aria-multiselectable' => 'true'
141
158
  end
142
159
 
143
160
  def accordion title, content, collapse_id=card.cardname.safe_key
144
161
  panel_body =
145
162
  case content
146
- when Hash
147
- accordion_group accordion(content, collapse_id)
148
- when Array
149
- content.join "\n"
150
- else
151
- content
163
+ when Hash then accordion_group accordion(content, collapse_id)
164
+ when Array then content.join "\n"
165
+ else content
152
166
  end
153
167
  %{
154
168
  <div class="panel panel-default">
155
169
  <div class="panel-heading" role="tab" id="heading-#{collapse_id}">
156
170
  <h4 class="panel-title">
157
- <a data-toggle="collapse" data-parent="#accordion-#{collapse_id}" href="##{collapse_id}" aria-expanded="true" aria-controls="#{collapse_id}">
158
- #{ title }
171
+ <a data-toggle="collapse" data-parent="#accordion-#{collapse_id}" \
172
+ href="##{collapse_id}" aria-expanded="true" \
173
+ aria-controls="#{collapse_id}">
174
+ #{title}
159
175
  </a>
160
176
  </h4>
161
177
  </div>
162
- <div id="#{collapse_id}" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-#{collapse_id}">
178
+ <div id="#{collapse_id}" class="panel-collapse collapse" \
179
+ role="tabpanel" aria-labelledby="heading-#{collapse_id}">
163
180
  <div class="panel-body">
164
- #{ panel_body }
181
+ #{panel_body}
165
182
  </div>
166
183
  </div>
167
184
  </div>
@@ -170,6 +187,5 @@ format :html do
170
187
  end
171
188
 
172
189
 
173
-
174
190
  # ~~~~~~~~~~~ below autogenerated; above pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/utils.rb ~~~~~~~~~~~
175
191
  end;end;end;end;
@@ -4,10 +4,9 @@ class Card; module Set; module All; module Actions; extend Card::Set
4
4
  # -*- encoding : utf-8 -*-
5
5
 
6
6
  def select_action_by_params params
7
- if (action = find_action_by_params(params))
8
- run_callbacks :select_action do
9
- self.selected_action_id = action.id
10
- end
7
+ return unless (action = find_action_by_params(params))
8
+ run_callbacks :select_action do
9
+ self.selected_action_id = action.id
11
10
  end
12
11
  end
13
12
 
@@ -15,28 +14,32 @@ def find_action_by_params args
15
14
  if args[:rev]
16
15
  nth_action args[:rev]
17
16
  elsif Integer === args[:rev_id] || args[:rev_id] =~ /^\d+$/
18
- if action = Action.fetch(args[:rev_id]) and action.card_id == id
17
+ if (action = Action.fetch(args[:rev_id])) && action.card_id == id
19
18
  action
20
19
  end
21
- elsif args[:rev_id] # revision id is probalby a mod (e.g. if you request files/:logo/05_standard.png)
20
+ # revision id is probalby a mod (e.g. if you request
21
+ # files/:logo/05_standard.png)
22
+ elsif args[:rev_id]
22
23
  last_action
23
24
  end
24
25
  end
25
26
 
26
27
  def nth_action index
27
28
  index = index.to_i
28
- if id and index > 0
29
- Action.where("draft is not true AND card_id = #{id}").order(:id).limit(1).offset(index-1).first
30
- end
29
+ return unless id && index > 0
30
+ Action.where("draft is not true AND card_id = #{id}")
31
+ .order(:id).limit(1).offset(index - 1).first
31
32
  end
32
33
 
33
34
  def revision action
34
- # a "revision" refers to the state of all tracked fields at the time of a given action
35
+ # a "revision" refers to the state of all tracked fields
36
+ # at the time of a given action
35
37
  if action.is_a? Integer
36
38
  action = Card::Action.fetch(action)
37
39
  end
38
- action and Card::TRACKED_FIELDS.inject({}) do |attr_changes, field|
39
- last_change = action.card_changes.find_by_field_name(field) || last_change_on(field, not_after: action)
40
+ action && Card::TRACKED_FIELDS.inject({}) do |attr_changes, field|
41
+ last_change = action.card_changes.find_by_field_name(field) ||
42
+ last_change_on(field, not_after: action)
40
43
  attr_changes[field.to_sym] = (last_change ? last_change.value : self[field])
41
44
  attr_changes
42
45
  end
@@ -45,15 +48,16 @@ end
45
48
  def delete_old_actions
46
49
  Card::TRACKED_FIELDS.each do |field|
47
50
  # assign previous changes on each tracked field to the last action
48
- if (la = last_action) && !la.change_for(field).present? and (last_change = last_change_on(field))
49
- last_change = Card::Change.find(last_change.id) # last_change comes as readonly record
51
+ if (la = last_action) && !la.change_for(field).present? &&
52
+ (last_change = last_change_on field)
53
+ # last_change comes as readonly record
54
+ last_change = Card::Change.find(last_change.id)
50
55
  last_change.update_attributes!(card_action_id: last_action_id)
51
56
  end
52
57
  end
53
- actions.where('id != ?', last_action_id ).delete_all
58
+ actions.where('id != ?', last_action_id).delete_all
54
59
  end
55
60
 
56
61
 
57
-
58
62
  # ~~~~~~~~~~~ below autogenerated; above pulled from /Users/ethan/dev/wagn/gem/card/mod/01_history/set/all/actions.rb ~~~~~~~~~~~
59
63
  end;end;end;end;