card 1.101.0 → 1.101.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/config/locales/en.yml +9 -6
  4. data/db/migrate_core_cards/data/decko_logo.svg +1 -59
  5. data/lib/card.rb +3 -0
  6. data/lib/card/content/diff/result.rb +40 -29
  7. data/lib/card/env.rb +2 -2
  8. data/lib/card/model/save_helper.rb +16 -182
  9. data/lib/card/model/save_helper/save_arguments.rb +94 -0
  10. data/lib/card/model/save_helper/save_helper_helper.rb +93 -0
  11. data/lib/card/name/all.rb +125 -0
  12. data/lib/card/name/all/class_methods.rb +28 -0
  13. data/lib/card/name/all/descendants.rb +46 -0
  14. data/lib/card/name/all/parts.rb +67 -0
  15. data/lib/card/query.rb +7 -2
  16. data/lib/card/query/card_query/interpretation.rb +2 -2
  17. data/lib/card/query/card_query/sorting.rb +12 -4
  18. data/lib/card/query/sql_statement.rb +1 -1
  19. data/lib/card/set/advanced_api.rb +8 -5
  20. data/lib/card/set/event/options.rb +13 -5
  21. data/lib/card/set/format.rb +16 -9
  22. data/lib/card/set/trait.rb +11 -8
  23. data/lib/card/subcards/add.rb +3 -24
  24. data/lib/card/subcards/args.rb +42 -0
  25. data/lib/card/tasks/card/file_card_creator/output_helper.rb +15 -10
  26. data/lib/card/view/options.rb +2 -1
  27. data/lib/card/view/permission.rb +14 -3
  28. data/lib/cardio.rb +9 -66
  29. data/lib/cardio/defaults.yml +70 -0
  30. data/lib/cardio/migration.rb +1 -1
  31. data/mod/core/set/all/assign_attributes.rb +8 -21
  32. data/mod/core/set/all/initialize.rb +9 -9
  33. data/mod/core/set/all/name_events.rb +3 -1
  34. data/mod/core/set/all/references.rb +2 -2
  35. data/mod/{settings → core}/set/right/autoname.rb +0 -0
  36. data/mod/{settings → core}/set/self/autoname.rb +0 -0
  37. data/mod/core/set/type/cardtype.rb +28 -0
  38. data/mod/{standard → core}/spec/set/type/cardtype_spec.rb +3 -24
  39. data/mod/standard/file/logo/image-original.svg +1 -59
  40. metadata +16 -27
  41. data/config/initializers/uuid_state_file.rb +0 -3
  42. data/mod/Modfile +0 -4
  43. data/mod/core/set/all/name.rb +0 -229
  44. data/mod/core/spec/set/all/name_spec.rb +0 -11
  45. data/mod/standard/set/all/rich_html/html_views/info.rb +0 -84
  46. data/mod/standard/set/type/cardtype.rb +0 -119
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2a2adcadfe25b2b8f3346896851f1abee137ac78420c53a0b043c316f1841d7
4
- data.tar.gz: 42c901e4d5d0822c48300a137e98d414ba742a778941906020829c7efa6c5e52
3
+ metadata.gz: 953dba50deba8e3b104b8caab032ddae23e4127a3b13dfefa90b1f5b72b13867
4
+ data.tar.gz: 6e0fee19ff4bb0eb6141cd57cf1bcddace1acc2286ea2315eb7d9976fcaaa5c4
5
5
  SHA512:
6
- metadata.gz: e3bd0bd661fcef00cb6f9d416805538b0b333bfc2f2e761dddff9dfa919fbb359654ba79390273e6b9e4d016766b5eabe1c03e30c2f3818ffc13fae72e3b1d14
7
- data.tar.gz: ee57e12d8a067ecefc988e5d3cb69a558bdea9d54cc1dd827148458cc00fdf89c29ff3a90e7791413a02cac8dc14fc97e7f5b19f1b30be6d5c043502837977a9
6
+ metadata.gz: e5f7cac62d75acc245dedc32be5806369222dabf16176bab11ce415a301384369b0bf23d79ef65fc5659e9b0d1f31231a8d103e925cae88dbb8b88bd375a5b89
7
+ data.tar.gz: eecb87ea692bde6079b689b2fd1814fcd16507f7e42bce43e1f1b35368628d47649e1609de574f87fc918fdb1ee9fd4553e7ee83a1a5189626f59c7b3644b332
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.0
1
+ 0.11.1
@@ -141,6 +141,11 @@ en:
141
141
  error_hard_templated: can't be changed because %{name} is hard templated to %{type_name}
142
142
  utils:
143
143
  exception_almost_deleted: Narrowly averted deleting current file
144
+ type:
145
+ cardtype:
146
+ cards_exist: Sorry, this card must remain a Cardtype so long as there are %{cardname} cards.
147
+ error_cant_alter: can't alter this type; %{name} cards still exist
148
+ error_invalid_character_in_cardtype: "may not contain any of the following characters: %{banned}"
144
149
  set_pattern:
145
150
  :01_all:
146
151
  label_set_all_cards: All cards
@@ -212,12 +217,6 @@ en:
212
217
  memory_diff: memory diff
213
218
  megabyte_suffix: M
214
219
  type:
215
- cardtype:
216
- cards_exist: Sorry, this card must remain a Cardtype so long as there are %{cardname} cards.
217
- add_card: Add %{cardname}
218
- configure_card: Configure %{cardname}
219
- error_cant_alter: can't alter this type; %{name} cards still exist
220
- error_invalid_character_in_cardtype: "may not contain any of the following characters: %{banned}"
221
220
  search_type:
222
221
  no_limit_exception: OH NO.. no limit
223
222
  no_content_exception: "Error in card '%{name}': can't run search with empty content"
@@ -314,6 +313,10 @@ en:
314
313
  exception_not_set_path: "not a set path: %{path}"
315
314
  content_in_file: Content is stored in file and can't be edited.
316
315
  type:
316
+ cardtype:
317
+ cards_exist: Sorry, this card must remain a Cardtype so long as there are %{cardname} cards.
318
+ add_card: Add %{cardname}
319
+ configure_card: Configure %{cardname}
317
320
  pointer:
318
321
  label_select: Select
319
322
  #description: description
@@ -1,59 +1 @@
1
- <svg style="min-width: 65px; min-height: 45px; margin-top: -16px; margin-bottom: -16px;" viewBox="0 0 242 220" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
2
- <!-- Generator: Sketch 46.2 (44496) - http://www.bohemiancoding.com/sketch -->
3
- <title>b&amp;w_logo</title>
4
- <desc>Created with Sketch.</desc>
5
- <defs>
6
- <rect id="path-1" x="35.3297422" y="10.484836" width="157.279595" height="190.607432" rx="12.491335"></rect>
7
- <filter x="-12.1%" y="-10.5%" width="125.4%" height="121.0%" filterUnits="objectBoundingBox" id="filter-2">
8
- <feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
9
- <feOffset dx="1" dy="0" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
10
- <feGaussianBlur stdDeviation="5.5" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
11
- <feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
12
- </filter>
13
- <rect id="path-3" x="51.9878879" y="19.404077" width="123.9533" height="171.161486" rx="9.6888466"></rect>
14
- <filter x="-15.3%" y="-11.7%" width="132.3%" height="123.4%" filterUnits="objectBoundingBox" id="filter-4">
15
- <feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
16
- <feOffset dx="1" dy="0" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
17
- <feGaussianBlur stdDeviation="5.5" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
18
- <feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
19
- </filter>
20
- <path d="M70.1050368,35.6666109 L159.089911,35.6666109 L159.089911,35.6666109 C163.678051,35.6666109 167.397473,39.386033 167.397473,43.9741728 L167.397473,87.717145 L167.397473,166.808436 L167.397473,166.808436 C167.397473,171.396576 163.678051,175.115998 159.089911,175.115998 L70.1050368,175.115998 L70.1050368,175.115998 C65.516897,175.115998 61.7974749,171.396576 61.7974749,166.808436 L61.7974749,43.9741728 L61.7974749,43.9741728 C61.7974749,39.386033 65.516897,35.6666109 70.1050368,35.6666109 Z" id="path-5"></path>
21
- <filter x="-18.0%" y="-14.3%" width="137.9%" height="128.7%" filterUnits="objectBoundingBox" id="filter-6">
22
- <feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
23
- <feOffset dx="1" dy="0" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
24
- <feGaussianBlur stdDeviation="5.5" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
25
- <feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
26
- </filter>
27
- <rect id="path-7" x="70.7637805" y="49.8525134" width="92.149175" height="107.18743" rx="7.8659801"></rect>
28
- <filter x="-20.6%" y="-18.7%" width="143.4%" height="137.3%" filterUnits="objectBoundingBox" id="filter-8">
29
- <feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
30
- <feOffset dx="1" dy="0" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
31
- <feGaussianBlur stdDeviation="5.5" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
32
- <feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.102553216 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
33
- </filter>
34
- </defs>
35
- <g id="Page-3" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
36
- <g id="b&amp;w_logo" fill-rule="nonzero">
37
- <g id="Decko-Logo-" transform="translate(7.000000, 4.000000)">
38
- <g id="g5642">
39
- <g id="svg-card-1" transform="translate(113.969540, 105.788552) scale(-1, 1) rotate(105.855860) translate(-113.969540, -105.788552) ">
40
- <use fill="black" fill-opacity="1" filter="url(#filter-2)" xlink:href="#path-1"></use>
41
- <use fill="#4D4D4D" fill-rule="evenodd" xlink:href="#path-1"></use>
42
- </g>
43
- <g id="svg-card-2" opacity="0.879999995" transform="translate(113.964538, 104.984820) scale(-1, 1) rotate(117.480003) translate(-113.964538, -104.984820) ">
44
- <use fill="black" fill-opacity="1" filter="url(#filter-4)" xlink:href="#path-3"></use>
45
- <use fill="#FFFFFF" fill-rule="evenodd" xlink:href="#path-3"></use>
46
- </g>
47
- <g id="svg-card-3" transform="translate(114.597474, 105.391304) scale(-1, 1) rotate(133.539993) translate(-114.597474, -105.391304) ">
48
- <use fill="black" fill-opacity="1" filter="url(#filter-6)" xlink:href="#path-5"></use>
49
- <use fill="#4C4C4C" fill-rule="evenodd" xlink:href="#path-5"></use>
50
- </g>
51
- <g id="svg-card-4" opacity="0.879999995" transform="translate(116.838368, 103.446228) scale(-1, 1) rotate(142.690002) translate(-116.838368, -103.446228) ">
52
- <use fill="black" fill-opacity="1" filter="url(#filter-8)" xlink:href="#path-7"></use>
53
- <use fill="#FFFFFF" fill-rule="evenodd" xlink:href="#path-7"></use>
54
- </g>
55
- </g>
56
- </g>
57
- </g>
58
- </g>
59
- </svg>
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="min-width:65px;min-height:45px;margin-top:-16px;margin-bottom:-16px" version="1.1" viewBox="0 0 242 220"><title>b&amp;w_logo</title><desc>Created with Sketch.</desc><defs><rect id="path-1" width="157.28" height="190.607" x="35.33" y="10.485" rx="12.491"/><filter id="filter-2" width="125.4%" height="121%" x="-12.1%" y="-10.5%" filterUnits="objectBoundingBox"><feMorphology in="SourceAlpha" operator="dilate" radius="1" result="shadowSpreadOuter1"/><feOffset dx="1" dy="0" in="shadowSpreadOuter1" result="shadowOffsetOuter1"/><feGaussianBlur in="shadowOffsetOuter1" result="shadowBlurOuter1" stdDeviation="5.5"/><feColorMatrix in="shadowBlurOuter1" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0"/></filter><rect id="path-3" width="123.953" height="171.161" x="51.988" y="19.404" rx="9.689"/><filter id="filter-4" width="132.3%" height="123.4%" x="-15.3%" y="-11.7%" filterUnits="objectBoundingBox"><feMorphology in="SourceAlpha" operator="dilate" radius="1" result="shadowSpreadOuter1"/><feOffset dx="1" dy="0" in="shadowSpreadOuter1" result="shadowOffsetOuter1"/><feGaussianBlur in="shadowOffsetOuter1" result="shadowBlurOuter1" stdDeviation="5.5"/><feColorMatrix in="shadowBlurOuter1" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0"/></filter><path id="path-5" d="M70.1050368,35.6666109 L159.089911,35.6666109 L159.089911,35.6666109 C163.678051,35.6666109 167.397473,39.386033 167.397473,43.9741728 L167.397473,87.717145 L167.397473,166.808436 L167.397473,166.808436 C167.397473,171.396576 163.678051,175.115998 159.089911,175.115998 L70.1050368,175.115998 L70.1050368,175.115998 C65.516897,175.115998 61.7974749,171.396576 61.7974749,166.808436 L61.7974749,43.9741728 L61.7974749,43.9741728 C61.7974749,39.386033 65.516897,35.6666109 70.1050368,35.6666109 Z"/><filter id="filter-6" width="137.9%" height="128.7%" x="-18%" y="-14.3%" filterUnits="objectBoundingBox"><feMorphology in="SourceAlpha" operator="dilate" radius="1" result="shadowSpreadOuter1"/><feOffset dx="1" dy="0" in="shadowSpreadOuter1" result="shadowOffsetOuter1"/><feGaussianBlur in="shadowOffsetOuter1" result="shadowBlurOuter1" stdDeviation="5.5"/><feColorMatrix in="shadowBlurOuter1" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 0"/></filter><rect id="path-7" width="92.149" height="107.187" x="70.764" y="49.853" rx="7.866"/><filter id="filter-8" width="143.4%" height="137.3%" x="-20.6%" y="-18.7%" filterUnits="objectBoundingBox"><feMorphology in="SourceAlpha" operator="dilate" radius="1" result="shadowSpreadOuter1"/><feOffset dx="1" dy="0" in="shadowSpreadOuter1" result="shadowOffsetOuter1"/><feGaussianBlur in="shadowOffsetOuter1" result="shadowBlurOuter1" stdDeviation="5.5"/><feColorMatrix in="shadowBlurOuter1" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.102553216 0"/></filter></defs><g id="Page-3" fill="none" fill-rule="evenodd" stroke="none" stroke-width="1"><g id="b&amp;w_logo" fill-rule="nonzero"><g id="Decko-Logo-" transform="translate(7.000000, 4.000000)"><g id="g5642"><g id="svg-card-1" transform="translate(113.969540, 105.788552) scale(-1, 1) rotate(105.855860) translate(-113.969540, -105.788552)"><use fill="#000" fill-opacity="1" filter="url(#filter-2)" xlink:href="#path-1"/><use fill="#4D4D4D" fill-rule="evenodd" xlink:href="#path-1"/></g><g id="svg-card-2" opacity=".88" transform="translate(113.964538, 104.984820) scale(-1, 1) rotate(117.480003) translate(-113.964538, -104.984820)"><use fill="#000" fill-opacity="1" filter="url(#filter-4)" xlink:href="#path-3"/><use fill="#FFF" fill-rule="evenodd" xlink:href="#path-3"/></g><g id="svg-card-3" transform="translate(114.597474, 105.391304) scale(-1, 1) rotate(133.539993) translate(-114.597474, -105.391304)"><use fill="#000" fill-opacity="1" filter="url(#filter-6)" xlink:href="#path-5"/><use fill="#4C4C4C" fill-rule="evenodd" xlink:href="#path-5"/></g><g id="svg-card-4" opacity=".88" transform="translate(116.838368, 103.446228) scale(-1, 1) rotate(142.690002) translate(-116.838368, -103.446228)"><use fill="#000" fill-opacity="1" filter="url(#filter-8)" xlink:href="#path-7"/><use fill="#FFF" fill-rule="evenodd" xlink:href="#path-7"/></g></g></g></g></g></svg>
data/lib/card.rb CHANGED
@@ -113,9 +113,12 @@ ActiveSupport.run_load_hooks(:before_card, self)
113
113
  class Card < ApplicationRecord
114
114
  extend Mark
115
115
  extend Dirty::MethodFactory
116
+ extend Name::All::ClassMethods
117
+
116
118
  include Dirty
117
119
  include DirtyNames
118
120
  include Director::CardMethods
121
+ include Name::All
119
122
 
120
123
  Card::Cache # trigger autoload
121
124
 
@@ -21,13 +21,13 @@ class Card
21
21
 
22
22
  def write_added_chunk text
23
23
  @adds_cnt += 1
24
- @complete << Card::Content::Diff.render_added_chunk(text)
24
+ @complete << Diff.render_added_chunk(text)
25
25
  @summary.add text
26
26
  end
27
27
 
28
28
  def write_deleted_chunk text
29
29
  @dels_cnt += 1
30
- @complete << Card::Content::Diff.render_deleted_chunk(text)
30
+ @complete << Diff.render_deleted_chunk(text)
31
31
  @summary.delete text
32
32
  end
33
33
 
@@ -78,42 +78,46 @@ class Card
78
78
  end
79
79
 
80
80
  def omits_content?
81
- @content_omitted || @remaining_chars < 0
81
+ @content_omitted || @remaining_chars.negative?
82
82
  end
83
83
 
84
84
  private
85
85
 
86
86
  def add_chunk text, action
87
- if @remaining_chars > 0
88
- @chunks << { action: action, text: text }
89
- @remaining_chars -= text.size
90
- end
87
+ return unless @remaining_chars.positive?
88
+
89
+ add_chunk_to_list text, action
90
+ @remaining_chars -= text.size
91
+ end
92
+
93
+ def add_chunk_to_list text, action
94
+ @chunks << { action: action, text: text }
91
95
  end
92
96
 
93
97
  def render_chunk action, text
94
98
  case action
95
99
  when "+", :added
96
- Card::Content::Diff.render_added_chunk text
100
+ Diff.render_added_chunk text
97
101
  when "-", :deleted
98
- Card::Content::Diff.render_deleted_chunk text
102
+ Diff.render_deleted_chunk text
99
103
  else text
100
104
  end
101
105
  end
102
106
 
103
107
  def truncate_overlap
104
- return unless @remaining_chars < 0
108
+ return unless @remaining_chars.negative?
105
109
 
106
110
  process_ellipsis
107
-
108
111
  index = @chunks.size - 1
109
112
  while @remaining_chars < @joint.size && index >= 0
110
- overlap_size = @remaining_chars + @chunks[index][:text].size
111
- break if process_overlap overlap_size, index
112
-
113
- index -= 1
113
+ process_overlap(index) ? break : (index -= 1)
114
114
  end
115
115
  end
116
116
 
117
+ def chunk_text index
118
+ @chunks[index][:text]
119
+ end
120
+
117
121
  def process_ellipsis
118
122
  return unless @chunks.last[:action] == :ellipsis
119
123
 
@@ -122,34 +126,41 @@ class Card
122
126
  @remaining_chars += @joint.size
123
127
  end
124
128
 
125
- def process_overlap overlap_size, index
129
+ def process_overlap index
130
+ return true if overlap_finished index
131
+
132
+ @remaining_chars += chunk_text(index).size
133
+ @chunks.delete_at(index)
134
+ false
135
+ end
136
+
137
+ def overlap_finished index
138
+ overlap_size = @remaining_chars + chunk_text(index).size
126
139
  if overlap_size == @joint.size
127
140
  replace_with_joint index
128
- true
129
141
  elsif overlap_size > @joint.size
130
142
  cut_with_joint index
131
- true
132
143
  else
133
- @remaining_chars += @chunks[index][:text].size
134
- @chunks.delete_at(index)
135
- false
144
+ return false
136
145
  end
146
+ true
137
147
  end
138
148
 
139
149
  def cut_with_joint index
140
- @chunks[index][:text] =
141
- @chunks[index][:text][0..(@remaining_chars - @joint.size - 1)]
150
+ cut_range = 0..(@remaining_chars - @joint.size - 1)
151
+ @chunks[index][:text] = chunk_text(index)[cut_range]
142
152
  @chunks[index][:text] += @joint
143
153
  end
144
154
 
145
155
  def replace_with_joint index
146
156
  @chunks.pop
147
- if index - 1 >= 0
148
- if @chunks[index - 1][:action] == :added
149
- @chunks << { action: :ellipsis, text: @joint }
150
- elsif @chunks[index - 1][:action] == :deleted
151
- @chunks << { action: :added, text: @joint }
152
- end
157
+ return unless index.positive?
158
+
159
+ case @chunks[index - 1][:action]
160
+ when :added
161
+ add_chunk_to_list @joint, :ellipsis
162
+ when :deleted
163
+ add_chunk_to_list @joint, :added
153
164
  end
154
165
  end
155
166
  end
data/lib/card/env.rb CHANGED
@@ -34,7 +34,7 @@ class Card
34
34
  end
35
35
 
36
36
  def params
37
- self[:params] ||= {}
37
+ self[:params] ||= {} # .with_indifferent_access
38
38
  end
39
39
 
40
40
  def with_params hash
@@ -42,7 +42,7 @@ class Card
42
42
  params.merge! hash
43
43
  yield
44
44
  ensure
45
- self.params = old_params
45
+ self[:params] = old_params
46
46
  end
47
47
 
48
48
  def hash hashish
@@ -9,22 +9,34 @@ class Card
9
9
  # All !-methods in this module rename existing cards
10
10
  # to resolve name conflicts)
11
11
  module SaveHelper
12
+ include SaveHelperHelper
13
+ include SaveArguments
14
+
12
15
  def with_user user_name
13
- Card::Auth.with current_id: Card.fetch_id(user_name) do
14
- yield
15
- end
16
+ Card::Auth.with(current_id: Card.fetch_id(user_name)) { yield }
16
17
  end
17
18
 
18
19
  def create_card name_or_args, content_or_args=nil
19
20
  Card.create! create_args(name_or_args, content_or_args)
20
21
  end
21
22
 
23
+ # if card with same name exists move it out of the way
24
+ def create_card! name_or_args, content_or_args=nil
25
+ args = standardize_args name_or_args, content_or_args
26
+ create_card args.reverse_merge(rename_if_conflict: :old)
27
+ end
28
+
22
29
  def update_card name, content_or_args
23
30
  args = standardize_update_args name, content_or_args
24
31
  resolve_name_conflict args
25
32
  Card[name]&.update! args
26
33
  end
27
34
 
35
+ def update_card! name, content_or_args
36
+ args = standardize_update_args name, content_or_args
37
+ update_card name, args.reverse_merge(rename_if_conflict: :new)
38
+ end
39
+
28
40
  def create_or_update_card name_or_args, content_or_args=nil
29
41
  name = name_from_args name_or_args
30
42
 
@@ -51,12 +63,6 @@ class Card
51
63
  card.delete!
52
64
  end
53
65
 
54
- def delete_code_card? name
55
- return false if name.is_a?(Symbol) && !Codename.exist?(name)
56
-
57
- Card.exist? name
58
- end
59
-
60
66
  # create if card doesn't exist
61
67
  # updates existing card only if given attributes are different except the
62
68
  # name
@@ -77,10 +83,6 @@ class Card
77
83
  ensure_card_simplified name, args
78
84
  end
79
85
 
80
- def codename_from_name name
81
- name.downcase.tr(" ", "_").tr(":*", "")
82
- end
83
-
84
86
  # create if card doesn't exist
85
87
  # updates existing card only if given attributes are different including
86
88
  # the name
@@ -112,31 +114,12 @@ class Card
112
114
  ensure_card [trait, :right, setting], card_args
113
115
  end
114
116
 
115
- # if card with same name exists move it out of the way
116
- def create_card! name_or_args, content_or_args=nil
117
- args = standardize_args name_or_args, content_or_args
118
- create_card args.reverse_merge(rename_if_conflict: :old)
119
- end
120
-
121
- def update_card! name, content_or_args
122
- args = standardize_update_args name, content_or_args
123
- update_card name, args.reverse_merge(rename_if_conflict: :new)
124
- end
125
-
126
117
  def create_or_update_card! name_or_args, content_or_args=nil
127
118
  args = standardize_args name_or_args, content_or_args
128
119
  create_or_update args.reverse_merge(rename_if_conflict: :new)
129
120
  end
130
121
 
131
- def add_style name, opts={}
132
- name.sub!(/^style\:?\s?/, "") # in case name is given with prefix
133
- # remove it so that we don't double it
134
-
135
- add_coderule_item name, "style",
136
- opts[:type_id] || Card::ScssID,
137
- opts[:to] || "*all+*style"
138
- end
139
-
122
+ # TODO: this is too specific for this
140
123
  def add_script name, opts={}
141
124
  name.sub!(/^script\:?\s?/, "") # in case name is given with prefix
142
125
  # remove it so that we don't double it
@@ -146,15 +129,6 @@ class Card
146
129
  opts[:to] || "*all+*script"
147
130
  end
148
131
 
149
- def add_coderule_item name, prefix, type_id, to
150
- codename = "#{prefix}_#{name.tr(' ', '_').underscore}"
151
- name = "#{prefix}: #{name}"
152
-
153
- ensure_card name, type_id: type_id,
154
- codename: codename
155
- Card[to].add_item! name
156
- end
157
-
158
132
  alias_method :create, :create_card
159
133
  alias_method :update, :update_card
160
134
  alias_method :create_or_update, :create_or_update_card
@@ -164,146 +138,6 @@ class Card
164
138
  alias_method :ensure, :ensure_card
165
139
  alias_method :ensure!, :ensure_card!
166
140
  alias_method :delete, :delete_card
167
-
168
- def method_missing method, *args
169
- method_name, cardtype_card = extract_cardtype_from_method_name method
170
- return super unless method_name
171
-
172
- sargs = standardize_args(*args)
173
- send "#{method_name}_card", sargs.merge(type_id: cardtype_card.id)
174
- end
175
-
176
- def respond_to_missing? method, _include_private=false
177
- extract_cardtype_from_method_name(method) || super
178
- end
179
-
180
- def extract_cardtype_from_method_name method
181
- return unless method =~ /^(?<method_name>create|ensure)_(?<type>.+?)(?:_card)?$/
182
-
183
- type = Regexp.last_match[:type]
184
- cardtype_card = Card::Codename[type.to_sym] ? Card[type.to_sym] : Card[type]
185
- return unless cardtype_card&.type_id == Card::CardtypeID ||
186
- cardtype_card&.id == Card::SetID
187
-
188
- [Regexp.last_match[:method_name], cardtype_card]
189
- end
190
-
191
- private
192
-
193
- def ensure_card_simplified name, args
194
- ensure_card_update(name, args) || Card.create!(add_name(name, args))
195
- end
196
-
197
- def ensure_card_update name, args
198
- card = Card[name]
199
- return unless card
200
-
201
- ensure_attributes card, args
202
- card
203
- rescue Card::Error::CodenameNotFound => _e
204
- false
205
- end
206
-
207
- def validate_setting setting
208
- unless Card::Codename.exist?(setting) &&
209
- Card.fetch_type_id(setting) == Card::SettingID
210
- raise ArgumentError, "not a valid setting: #{setting}"
211
- end
212
- end
213
-
214
- def normalize_trait_rule_args setting, value
215
- return value if value.is_a? Hash
216
-
217
- if Card.fetch_type_id([setting, :right, :default]) == Card::PointerID
218
- value = Array(value).to_pointer_content
219
- end
220
- { content: value }
221
- end
222
-
223
- # @return args
224
- def standardize_args name_or_args, content_or_args=nil, _ignore=nil
225
- if name_or_args.is_a?(Hash)
226
- name_or_args
227
- else
228
- add_name name_or_args, content_or_args || {}
229
- end
230
- end
231
-
232
- def hashify value_or_hash, key
233
- if value_or_hash.is_a?(Hash)
234
- value_or_hash
235
- elsif value_or_hash.nil?
236
- {}
237
- else
238
- { key => value_or_hash }
239
- end
240
- end
241
-
242
- def standardize_ensure_args name_or_args, content_or_args
243
- name = name_or_args.is_a?(Hash) ? name_or_args[:name] : name_or_args
244
- args = if name_or_args.is_a?(Hash)
245
- name_or_args
246
- else
247
- hashify content_or_args, :content
248
- end
249
- [name, args]
250
- end
251
-
252
- def standardize_update_args name_or_args, content_or_args
253
- return name_or_args if name_or_args.is_a?(Hash)
254
-
255
- hashify content_or_args, :content
256
- end
257
-
258
- def create_args name_or_args, content_or_args=nil
259
- args = standardize_args name_or_args, content_or_args
260
- resolve_name_conflict args
261
- args
262
- end
263
-
264
- def name_from_args name_or_args
265
- name_or_args.is_a?(Hash) ? name_or_args[:name] : name_or_args
266
- end
267
-
268
- def add_name name, content_or_args
269
- if content_or_args.is_a?(Hash)
270
- content_or_args.reverse_merge name: name
271
- else
272
- { content: content_or_args, name: name }
273
- end
274
- end
275
-
276
- def resolve_name_conflict args
277
- rename = args.delete :rename_if_conflict
278
- return unless args[:name] && rename
279
-
280
- args[:name] = Card.uniquify_name args[:name], rename
281
- end
282
-
283
- def ensure_attributes card, args
284
- subcards = card.extract_subcard_args! args
285
- update_args = changing_args card, args
286
-
287
- return if update_args.empty? && subcards.empty?
288
-
289
- # FIXME: use ensure_attributes for subcards
290
- card.update! update_args.merge(subcards: subcards, skip: :validate_renaming)
291
- end
292
-
293
- def changing_args card, args
294
- args.select do |key, value|
295
- if key =~ /^\+/
296
- subfields[key] = value
297
- false
298
- elsif key.to_sym == :name
299
- card.name.to_s != value
300
- elsif value.is_a? ::File
301
- # NOOP
302
- else
303
- card.send(key) != value
304
- end
305
- end
306
- end
307
141
  end
308
142
  end
309
143
  end