card 1.93.3 → 1.93.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/db/migrate/20170908114452_increase_text_size_for_delayed_jobs.rb +9 -0
  4. data/db/migrate_core_cards/data/cards/*header +2 -2
  5. data/lib/card/format/nest.rb +12 -5
  6. data/lib/card/format/nest/fetch.rb +1 -2
  7. data/lib/card/format/render.rb +2 -2
  8. data/lib/card/model/save_helper.rb +1 -1
  9. data/lib/card/set/format/haml_views.rb +7 -3
  10. data/lib/card/subcards.rb +27 -228
  11. data/lib/card/subcards/add.rb +121 -0
  12. data/lib/card/subcards/relate.rb +27 -0
  13. data/lib/card/subcards/remove.rb +42 -0
  14. data/lib/card/tasks/card/create.rake +35 -132
  15. data/lib/card/tasks/card/file_card_creator.rb +25 -0
  16. data/lib/card/tasks/card/file_card_creator/abstract_file_card.rb +44 -0
  17. data/lib/card/tasks/card/file_card_creator/abstract_file_card/migration_file.rb +49 -0
  18. data/lib/card/tasks/card/file_card_creator/abstract_file_card/ruby_file.rb +30 -0
  19. data/lib/card/tasks/card/file_card_creator/abstract_file_card/source_file.rb +36 -0
  20. data/lib/card/tasks/card/file_card_creator/haml_card.rb +42 -0
  21. data/lib/card/tasks/card/file_card_creator/output_helper.rb +50 -0
  22. data/lib/card/tasks/card/file_card_creator/script_card.rb +33 -0
  23. data/lib/card/tasks/card/file_card_creator/style_card.rb +25 -0
  24. data/lib/generators/card/template/template_generator.rb +1 -1
  25. data/mod/account/set/self/account_links.rb +1 -1
  26. data/mod/basic_formats/set/all/all_csv.rb +63 -0
  27. data/mod/basic_formats/set/all/json.rb +4 -1
  28. data/mod/bootstrap/db/migrate_cards/20170719163733_update_bootswatch_themes_to_4_beta.rb +5 -2
  29. data/mod/carrierwave/set/abstract/attachment.rb +1 -2
  30. data/mod/core/set/abstract/haml_file.rb +20 -0
  31. data/mod/core/set/all/chunk.rb +125 -0
  32. data/mod/core/set/all/collection.rb +2 -351
  33. data/mod/core/set/all/content.rb +26 -7
  34. data/mod/core/set/all/extended.rb +45 -0
  35. data/mod/core/set/all/haml.rb +3 -7
  36. data/mod/core/set/all/item.rb +92 -0
  37. data/mod/core/set/all/name.rb +36 -0
  38. data/mod/core/set/all/subcards.rb +21 -12
  39. data/mod/core/set/all/tabs.rb +50 -0
  40. data/mod/core/set/all/trash.rb +4 -0
  41. data/mod/core/spec/set/all/chunk_spec.rb +45 -0
  42. data/mod/core/spec/set/all/collection_spec.rb +6 -6
  43. data/mod/history/set/all/action_view.rb +1 -1
  44. data/mod/machines/lib/javascript/decko.js.coffee +3 -0
  45. data/mod/pointer/set/abstract/02_pointer/edit.rb +0 -2
  46. data/mod/search/set/abstract/search.rb +1 -1
  47. data/mod/search/set/all/filter.rb +0 -2
  48. data/mod/search/template/all/filter/_filter_input.haml +1 -1
  49. data/mod/search/template/all/filter/filter_form.haml +1 -1
  50. data/mod/standard/set/all/rich_html/editing.rb +1 -1
  51. data/mod/standard/set/all/rich_html/form.rb +6 -7
  52. data/mod/standard/set/all/rich_html/menu.rb +2 -3
  53. data/mod/standard/set/all/rich_html/toolbar.rb +3 -4
  54. data/mod/standard/set/type/cardtype.rb +1 -1
  55. data/mod/standard/spec/set/all/rich_html/editing_spec.rb +15 -4
  56. data/mod/tinymce_editor/db/migrate_cards/{20171113233150_update_tinymce_config.rb → 20171113233151_update_tinymce_config.rb} +1 -0
  57. metadata +25 -161
  58. data/.rspec +0 -4
  59. data/card.gemspec +0 -87
  60. data/db/seed/test/fixtures/.gitkeep +0 -0
  61. data/mod/bootstrap/vendor/bootstrap/.babelrc.js +0 -16
  62. data/mod/bootstrap/vendor/bootstrap/.editorconfig +0 -17
  63. data/mod/bootstrap/vendor/bootstrap/.eslintignore +0 -3
  64. data/mod/bootstrap/vendor/bootstrap/.gitattributes +0 -16
  65. data/mod/bootstrap/vendor/bootstrap/.github/CONTRIBUTING.md +0 -252
  66. data/mod/bootstrap/vendor/bootstrap/.github/ISSUE_TEMPLATE.md +0 -22
  67. data/mod/bootstrap/vendor/bootstrap/.gitignore +0 -46
  68. data/mod/bootstrap/vendor/bootstrap/.hound.yml +0 -19
  69. data/mod/bootstrap/vendor/bootstrap/.houndignore +0 -4
  70. data/mod/bootstrap/vendor/bootstrap/.travis.yml +0 -32
  71. data/mod/bootstrap/vendor/bootstrap/build/.htmllintrc +0 -19
  72. data/mod/bootstrap/vendor/bootstrap/build/.stylelintrc +0 -248
  73. data/mod/bootstrap/vendor/bootstrap/docs/4.0/examples/.stylelintrc +0 -12
  74. data/mod/bootstrap/vendor/bootstrap/js/.eslintrc.json +0 -240
  75. data/mod/bootstrap/vendor/bootstrap/js/tests/.eslintrc.json +0 -46
  76. data/mod/bootstrap/vendor/bootswatch/.gitignore +0 -7
  77. data/mod/bootstrap/vendor/bootswatch/.npmignore +0 -12
  78. data/mod/bootstrap/vendor/bootswatch/.travis.yml +0 -21
  79. data/mod/bootstrap/vendor/bootswatch/docs/.nojekyll +0 -0
  80. data/mod/bootstrap/vendor/bootswatch/docs/2/.travis.yml +0 -15
  81. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/bootstrap/.bower.json +0 -20
  82. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/bootstrap/.gitignore +0 -37
  83. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/bootstrap/.travis.yml +0 -3
  84. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/bootstrap/js/.jshintrc +0 -12
  85. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/jquery/.bower.json +0 -20
  86. data/mod/bootstrap/vendor/bootswatch/docs/2/bower_components/jquery/.gitignore +0 -1
  87. data/mod/bootstrap/vendor/bootswatch/docs/2/swatchmaker/.gitignore +0 -1
  88. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap-sass-official/.bower.json +0 -45
  89. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/.bower.json +0 -44
  90. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/grunt/.jshintrc +0 -7
  91. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/js/.jscsrc +0 -42
  92. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/js/.jshintrc +0 -15
  93. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/less/.csscomb.json +0 -304
  94. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/bootstrap/less/.csslintrc +0 -19
  95. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/font-awesome/.bower.json +0 -14
  96. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/font-awesome/.gitignore +0 -32
  97. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/html5shiv/.bower.json +0 -25
  98. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/jquery/.bower.json +0 -38
  99. data/mod/bootstrap/vendor/bootswatch/docs/3/bower_components/respond/.bower.json +0 -20
  100. data/mod/bootstrap/vendor/select2/.editorconfig +0 -6
  101. data/mod/bootstrap/vendor/select2/.github/CONTRIBUTING.md +0 -204
  102. data/mod/bootstrap/vendor/select2/.github/ISSUE_TEMPLATE.md +0 -46
  103. data/mod/bootstrap/vendor/select2/.github/PULL_REQUEST_TEMPLATE.md +0 -13
  104. data/mod/bootstrap/vendor/select2/.gitignore +0 -3
  105. data/mod/bootstrap/vendor/select2/.jshintignore +0 -4
  106. data/mod/bootstrap/vendor/select2/.jshintrc +0 -25
  107. data/mod/bootstrap/vendor/select2/.travis.yml +0 -22
  108. data/script/fetch_bootswatch_themes.rb +0 -38
  109. data/spec/config/initializers/core_extensions_spec.rb +0 -47
  110. data/spec/config/initializers/patches/active_job_spec.rb +0 -7
  111. data/spec/lib/card/action_spec.rb +0 -15
  112. data/spec/lib/card/auth_spec.rb +0 -58
  113. data/spec/lib/card/cache_spec.rb +0 -116
  114. data/spec/lib/card/chunk_spec.rb +0 -18
  115. data/spec/lib/card/codename_spec.rb +0 -66
  116. data/spec/lib/card/content_spec.rb +0 -428
  117. data/spec/lib/card/diff_spec.rb +0 -208
  118. data/spec/lib/card/format/nest_spec.rb +0 -13
  119. data/spec/lib/card/format/render_spec.rb +0 -26
  120. data/spec/lib/card/format_spec.rb +0 -117
  121. data/spec/lib/card/i18n_spec.rb +0 -24
  122. data/spec/lib/card/loader/Modfile +0 -2
  123. data/spec/lib/card/loader_spec.rb +0 -98
  124. data/spec/lib/card/migration/import_spec.rb +0 -80
  125. data/spec/lib/card/mod/loader/mod_dirs.rb +0 -8
  126. data/spec/lib/card/mod/loader/set_loader_spec.rb +0 -19
  127. data/spec/lib/card/mod/loader/set_pattern_loader_spec.rb +0 -19
  128. data/spec/lib/card/name/fields_and_traits_spec.rb +0 -18
  129. data/spec/lib/card/name_spec.rb +0 -70
  130. data/spec/lib/card/query/sorting_spec.rb +0 -68
  131. data/spec/lib/card/query_spec.rb +0 -574
  132. data/spec/lib/card/reference_spec.rb +0 -212
  133. data/spec/lib/card/set/event_spec.rb +0 -22
  134. data/spec/lib/card/set/trait_spec.rb +0 -80
  135. data/spec/lib/card/set_pattern_spec.rb +0 -59
  136. data/spec/lib/card/set_spec.rb +0 -89
  137. data/spec/lib/card/stage_director_spec.rb +0 -482
  138. data/spec/lib/card/subcards_spec.rb +0 -177
  139. data/spec/lib/card/success_spec.rb +0 -148
  140. data/spec/lib/card/view_cache_spec.rb +0 -27
  141. data/spec/mailers/mailer_spec.rb +0 -62
  142. data/spec/models/card/create_spec.rb +0 -119
  143. data/spec/models/card/trash_spec.rb +0 -189
  144. data/spec/models/card_spec.rb +0 -136
  145. data/spec/spec_helper.rb +0 -45
  146. data/spec/support/card_spec_helper.rb +0 -74
  147. data/spec/support/card_spec_loader.rb +0 -112
  148. data/spec/support/helper/card_helper.rb +0 -58
  149. data/spec/support/helper/event_helper.rb +0 -94
  150. data/spec/support/helper/render_helper.rb +0 -44
  151. data/spec/support/helper/save_helper.rb +0 -30
  152. data/spec/support/helper/set_helper.rb +0 -80
  153. data/spec/support/matchers/card_matchers.rb +0 -160
  154. data/spec/support/matchers/expectations.rb +0 -5
  155. data/spec/support/matchers/file_matchers.rb +0 -71
  156. data/spec/support/matchers/html_matchers.rb +0 -29
  157. data/spec/support/matchers/negated_matchers.rb +0 -2
  158. data/spec/support/simplecov_helper.rb +0 -70
  159. data/spec/support/test_mods/mod1/set/all/test_set.rb +0 -3
  160. data/spec/support/test_mods/mod2/set_pattern/test_pattern.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 199075c5dc749a22620b59dfa9804a8c44cd2efa
4
- data.tar.gz: e33773ececb04f233ae04572ac2e68695819383b
3
+ metadata.gz: 9ca5a3aee7c51d1ea3f43add1af3d85a71314af8
4
+ data.tar.gz: 0135ed52dec26c17de6a0d1c3232db8c3c41f9e9
5
5
  SHA512:
6
- metadata.gz: e58bc871b56f02b400d8901ec0737375d8e653b32cef27a85f92535639cf2870268f1631a7a72e087cfe37a3c84d341a640cdb71ad60badb92c98aeecde77f34
7
- data.tar.gz: df87056eaca1f05495b4dd1dfc0f32b2f0aca833ef6afdf83577c858d169121382ca0c6e8513d6b370d106a0315908de53e7ba9ff978bf5687c5d0abd76073cc
6
+ metadata.gz: f78b2dedc458c623bcd224b80104a2cd9af0b5815b826962cab302bb23f2cc087bb4fcf86ffd338ff1a718ed2a7cb8bb0b937469be0b04ed61d01bd7dba0c0e2
7
+ data.tar.gz: 5489766302152fc62b3fdcdc25d8f00ebb0449f52cb509a12b6a3bdbe6fd41dd043aadc1abe64f03ad083a7ddc4715eee5770ff14cecb280c6658464c5f25aef
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
@@ -0,0 +1,9 @@
1
+ class IncreaseTextSizeForDelayedJobs < ActiveRecord::Migration[5.1]
2
+ def self.up
3
+ change_column :delayed_jobs, :handler, :text, :limit => 16777215
4
+ end
5
+
6
+ def self.down
7
+ change_column :delayed_jobs, :handler, :text
8
+ end
9
+ end
@@ -2,10 +2,10 @@
2
2
  <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbar-collapse-1" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
3
3
  <span class="navbar-toggler-icon"></span>
4
4
  </button>
5
- <div class="navbar-brand">
5
+ <a class="navbar-brand" href="/">
6
6
  {{*logo|core;size:small}}
7
7
  {{*title|core}}
8
- </div>
8
+ </a>
9
9
  <div class="collapse navbar-collapse" id="navbar-collapse-1">
10
10
  <div class="navbar-nav mr-auto">
11
11
  {{*main menu|navbar_links}}
@@ -6,6 +6,13 @@ class Card
6
6
  include Subformat
7
7
  include Mode
8
8
 
9
+ def nest cardish, options={}, override=true, &block
10
+ return "" if nest_invisible?
11
+ nested_card = fetch_nested_card cardish, options
12
+ view, options = interpret_nest_options nested_card, options
13
+ nest_render nested_card, view, options, override, &block
14
+ end
15
+
9
16
  # nested by another card's content
10
17
  # (as opposed to a direct API nest)
11
18
  def content_nest opts={}
@@ -15,11 +22,11 @@ class Card
15
22
  nest nest_name, opts
16
23
  end
17
24
 
18
- def nest cardish, options={}, override=true, &block
19
- return "" if nest_invisible?
20
- nested_card = fetch_nested_card cardish, options
21
- view, options = interpret_nest_options nested_card, options
22
- nest_render nested_card, view, options, override, &block
25
+ # create a path for a nest with respect ot the nest options
26
+ def nest_path name, nest_opts={}
27
+ path_opts = { slot: nest_opts.clone }
28
+ path_opts[:view] = path_opts[:slot].delete :view
29
+ page_path name, path_opts
23
30
  end
24
31
 
25
32
  def interpret_nest_options nested_card, options
@@ -9,7 +9,7 @@ class Card
9
9
  when Symbol, Integer then Card.fetch cardish
10
10
  when "_", "_self" then card.context_card
11
11
  else
12
- opts[:nest_name] = cardish.to_s
12
+ opts[:nest_name] = Card::Name[cardish].to_s
13
13
  Card.fetch cardish, new: nest_new_args(opts)
14
14
  end
15
15
  end
@@ -53,7 +53,6 @@ class Card
53
53
  return unless (nestcard_params = subcard_params[nest_name])
54
54
  nestcard_params["content"]
55
55
  end
56
-
57
56
  end
58
57
  end
59
58
  end
@@ -17,9 +17,9 @@ class Card
17
17
  def with_voo voo
18
18
  old_voo = @voo
19
19
  @voo = voo
20
- result = yield
20
+ yield
21
+ ensure
21
22
  @voo = old_voo
22
- result
23
23
  end
24
24
 
25
25
  def view_options_with_defaults view, options
@@ -179,7 +179,7 @@ class Card
179
179
  end
180
180
 
181
181
  def ensure_attributes card, args
182
- args = args.to_h.with_indifferent_access
182
+ # args = args.to_h.with_indifferent_access
183
183
  subcards = card.extract_subcard_args! args
184
184
  update_args =
185
185
  args.select do |key, value|
@@ -44,12 +44,14 @@ class Card
44
44
  end
45
45
  end
46
46
 
47
- def haml_template_path view, source=nil
47
+ def haml_template_path view=nil, source=nil
48
48
  each_template_path(source) do |template_dir, source_dir|
49
49
  path = try_haml_template_path template_dir, view, source_dir
50
50
  return path if path
51
51
  end
52
- raise Card::Error, "can't find haml template for #{view}"
52
+ msg = "can't find haml template"
53
+ msg += " for #{view}" if view.present?
54
+ raise Card::Error, msg
53
55
  end
54
56
 
55
57
  def each_template_path source
@@ -62,7 +64,9 @@ class Card
62
64
  end
63
65
 
64
66
  def try_haml_template_path template_path, view, source_dir, ext="haml"
65
- path = ::File.expand_path("#{template_path}/#{view}.#{ext}", source_dir)
67
+ template_path = File.join(template_path, view.to_s) if view.present?
68
+ template_path += ".#{ext}"
69
+ path = ::File.expand_path(template_path, source_dir)
66
70
  .sub(%r{(/mod/[^/]+)/set/}, "\\1/#{TEMPLATE_DIR}/")
67
71
  ::File.exist?(path) && path
68
72
  end
@@ -1,14 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
 
3
3
  class Card
4
- def subcards
5
- @subcards ||= Subcards.new(self)
6
- end
7
-
8
- def expire_subcards
9
- subcards.clear
10
- end
11
-
12
4
  # API to create/update/delete additional cards together with the main card.
13
5
  # The most common case is for fields but subcards don't have to be descendants.
14
6
  #
@@ -19,59 +11,37 @@ class Card
19
11
  # Together with "my address" you want to create the subcards
20
12
  # "my address+name", "my address+street", etc.
21
13
  class Subcards
14
+ require_dependency "card/subcards/add"
15
+ require_dependency "card/subcards/remove"
16
+ require_dependency "card/subcards/relate"
17
+
18
+ include Add
19
+ include Remove
20
+ include Relate
21
+
22
22
  attr_accessor :context_card, :keys
23
23
  def initialize context_card
24
24
  @context_card = context_card
25
25
  @keys = ::Set.new
26
26
  end
27
27
 
28
- # @example Add a subcard with name 'spoiler'
29
- # add 'spoiler', type: 'Phrase', content: 'John Snow is a Targaryen'
30
- # card_obj = Card.new name: 'spoiler', type: 'Phrase',
31
- # content: 'John Snow is a Targaryen'
32
- # add card_obj
33
- # add name: 'spoiler', type: 'Phrase', content: 'John Snow is a Targaryen'
34
- #
35
- # @example Add a subcard that is added in the integration phase
36
- # (and hence doesn't hold up the transaction for the main card)
37
- # add 'spoiler', content: 'John Snow is a Targaryen',
38
- # transact_in_stage: :integrate
39
- # add card_obj, delayed: true
40
- def add name_or_card_or_attr, attr_or_opts={}
41
- case name_or_card_or_attr
42
- when Card
43
- new_by_card name_or_card_or_attr, attr_or_opts
44
- when Hash
45
- args = name_or_card_or_attr
46
- if args[:name]
47
- new_by_attributes args.delete(:name), args
48
- else
49
- multi_add args
50
- end
51
- else
52
- new_by_attributes name_or_card_or_attr, attr_or_opts
53
- end
28
+ def [] name
29
+ card(name) || field(name)
30
+ end
31
+
32
+ def field name
33
+ key = field_name_to_key name
34
+ fetch_subcard key if @keys.include? key
54
35
  end
55
36
 
56
- def add_child name, args
57
- name = name.is_a?(Symbol) ? name.cardname : name.to_name
58
- add name.prepend_joint, args
37
+ def card name
38
+ return unless @keys.include? name.to_name.key
39
+ fetch_subcard name
59
40
  end
60
- alias_method :add_field, :add_child
61
41
 
62
- def remove_child name_or_card
63
- if name_or_card.is_a? Card
64
- remove name_or_card
65
- else
66
- absolute_name = @context_card.name.field_name(name_or_card)
67
- if @keys.include? absolute_name.key
68
- remove absolute_name
69
- else
70
- remove @context_card.name.relative_field_name(name_or_card)
71
- end
72
- end
42
+ def present?
43
+ @keys.present?
73
44
  end
74
- alias_method :remove_field, :remove_child
75
45
 
76
46
  def catch_up_to_stage stage_index
77
47
  each_card do |subcard|
@@ -79,46 +49,12 @@ class Card
79
49
  end
80
50
  end
81
51
 
82
- def clear
83
- @keys.each do |key|
84
- if (subcard = fetch_subcard key)
85
- ActManager.delete subcard.director
86
- end
87
- Card.cache.soft.delete key
88
- end
89
- @keys = ::Set.new
90
- end
91
-
92
- def deep_clear cleared=::Set.new
93
- each_card do |card|
94
- next if cleared.include? card.id
95
- cleared << card.id
96
- card.subcards.deep_clear cleared
97
- end
98
- clear
99
- end
100
-
101
- def remove name_or_card
102
- key = subcard_key name_or_card
103
- return unless @keys.include? key
104
- @keys.delete key
105
- removed_card = fetch_subcard key
106
- removed_card.current_action.delete if removed_card.current_action
107
- ActManager.deep_delete removed_card.director
108
- Card.cache.soft.delete key
109
- removed_card
110
- end
111
-
112
52
  def rename old_name, new_name
113
53
  return unless @keys.include? old_name.to_name.key
114
54
  @keys.delete old_name.to_name.key
115
55
  @keys << new_name.to_name.key
116
56
  end
117
57
 
118
- def << value
119
- add value
120
- end
121
-
122
58
  def method_missing method, *args
123
59
  return unless @keys.respond_to? method
124
60
  @keys.send method, *args
@@ -146,163 +82,26 @@ class Card
146
82
  end
147
83
  end
148
84
 
149
- def []= name, card_or_attr
150
- case card_or_attr
151
- when Hash
152
- new_by_attributes name, card_or_attr
153
- when Card
154
- new_by_card card_or_attr
155
- end
156
- end
157
-
158
- def [] name
159
- card(name) || field(name)
160
- end
161
-
162
- def field name
163
- key = field_name_to_key name
164
- fetch_subcard key if @keys.include? key
165
- end
166
-
167
- def card name
168
- return unless @keys.include? name.to_name.key
169
- fetch_subcard name
170
- end
171
-
172
- def present?
173
- @keys.present?
85
+ def fetch_subcard key
86
+ Card.fetch key, local_only: true, new: {}
174
87
  end
175
88
 
176
89
  private
177
90
 
178
- # Handles hash with several subcards
179
- def multi_add args
180
- args.each_pair do |key, val|
181
- case val
182
- when String then new_by_attributes key, content: val
183
- when Card
184
- val.name = absolutize_subcard_name key
185
- new_by_card val
186
- when nil then next
187
- else new_by_attributes key, val
188
- end
189
- end
190
- end
191
-
192
- def subcard_key name_or_card
193
- key = case name_or_card
194
- when Card
195
- name_or_card.key
196
- when Symbol
197
- fetch_subcard(name_or_card).key
198
- else
199
- name_or_card.to_name.key
91
+ def subcard_key cardish
92
+ key = case cardish
93
+ when Card then cardish.key
94
+ when Symbol then fetch_subcard(cardish).key
95
+ else cardish.to_name.key
200
96
  end
201
97
  key = absolutize_subcard_name(key).key unless @keys.include?(key)
202
98
  key
203
99
  end
204
100
 
205
- def fetch_subcard key
206
- Card.fetch key, local_only: true, new: {}
207
- end
208
-
209
- def field_name_to_key name
210
- if @context_card.name =~ /^\+/
211
- @context_card.name.relative_field_name(name).key
212
- else
213
- absolute_key = @context_card.name.field_name(name).key
214
- if @keys.include? absolute_key
215
- absolute_key
216
- else
217
- @context_card.name.relative_field_name(name).key
218
- end
219
- end
220
- end
221
-
222
- # TODO: this method already exists as card instance method in
223
- # tracked_attributes.rb. Find a place for it where its accessible
224
- # for both. There is one important difference. The keys are symbols
225
- # here instead of strings
226
- def extract_subcard_args! name, args
227
- subcards = args.delete(:subcards) || {}
228
- if (subfields = args.delete(:subfields))
229
- subfields.each_pair do |key, value|
230
- subcards[name.to_name.field(key)] = value
231
- end
232
- end
233
- args.keys.each do |key|
234
- subcards[key] = args.delete(key) if key =~ /^\+/
235
- end
236
- subcards
237
- end
238
-
239
- def new_by_attributes name, attributes={}
240
- attributes ||= {}
241
- absolute_name = absolutize_subcard_name name
242
- if absolute_name.field_of?(@context_card.name) &&
243
- (absolute_name.parts.size - @context_card.name.parts.size) > 2
244
- left_card = new_by_attributes absolute_name.left
245
- new_by_card left_card, transact_in_stage: attributes[:transact_in_stage]
246
- left_card.subcards.new_by_attributes absolute_name, attributes
247
- else
248
- subcard_args = extract_subcard_args! name, attributes
249
- t_i_s = attributes.delete(:transact_in_stage)
250
- card = Card.assign_or_initialize_by absolute_name.s, attributes, local_only: true
251
- subcard = new_by_card card, transact_in_stage: t_i_s
252
- card.subcards.add subcard_args
253
- subcard
254
- end
255
- end
256
-
257
101
  def absolutize_subcard_name name
258
102
  name = Card::Name[name]
259
103
  return name if @context_card.name.parts.first.blank?
260
104
  name.absolute_name @context_card.name
261
105
  end
262
-
263
- def new_by_card card, opts={}
264
- card.supercard = @context_card
265
- if !card.name.simple? &&
266
- card.name.field_of?(@context_card.name)
267
- card.superleft = @context_card
268
- end
269
- @keys << card.key
270
- Card.write_to_soft_cache card
271
- card.director = @context_card.director.subdirectors.add(card, opts)
272
- card
273
- end
274
- end
275
-
276
- def right_id= card_or_id
277
- write_card_or_id :right_id, card_or_id
278
- end
279
-
280
- def left_id= card_or_id
281
- write_card_or_id :left_id, card_or_id
282
- end
283
-
284
- def type_id= card_or_id
285
- write_card_or_id :type_id, card_or_id
286
- end
287
-
288
- def write_card_or_id attribute, card_or_id
289
- if card_or_id.is_a? Card
290
- card = card_or_id
291
- if card.id
292
- write_attribute attribute, card.id
293
- else
294
- add_subcard card
295
- card.director.prior_store = true
296
- with_id_when_exists(card) do |id|
297
- write_attribute attribute, id
298
- end
299
- end
300
- else
301
- write_attribute attribute, card_or_id
302
- end
303
- end
304
-
305
- def with_id_when_exists card, &block
306
- card.director.call_after_store(&block)
307
106
  end
308
107
  end