card 1.15.7 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/card.gemspec +3 -2
  4. data/config/initializers/inflections.rb +1 -1
  5. data/db/migrate_core_cards/20150528084659_add_session_cardtype.rb +0 -1
  6. data/db/migrate_core_cards/20150601133433_add_recent_setting_session_card.rb +12 -0
  7. data/db/migrate_core_cards/20150610171702_add_debugger_session_card.rb +11 -0
  8. data/db/migrate_core_cards/20150611203506_rails_inflection_updates.rb +82 -0
  9. data/db/migrate_core_cards/20150627205133_fix_script_bootstrap_card_type.rb +7 -0
  10. data/db/migrate_core_cards/20150702130543_remove_edit_toolbar_pinned.rb +9 -0
  11. data/db/schema.rb +81 -81
  12. data/db/seed/new/card_actions.yml +12581 -1647
  13. data/db/seed/new/card_acts.yml +1 -1
  14. data/db/seed/new/card_changes.yml +39326 -7569
  15. data/db/seed/new/card_references.yml +518 -455
  16. data/db/seed/new/cards.yml +1547 -1291
  17. data/db/seed/test/fixtures/card_actions.yml +13700 -2717
  18. data/db/seed/test/fixtures/card_acts.yml +314 -272
  19. data/db/seed/test/fixtures/card_changes.yml +45409 -13573
  20. data/db/seed/test/fixtures/card_references.yml +1223 -1125
  21. data/db/seed/test/fixtures/cards.yml +2694 -2433
  22. data/db/seed/test/fixtures/file1.txt +1 -0
  23. data/db/seed/test/fixtures/file2.txt +1 -0
  24. data/db/version_core_cards.txt +1 -1
  25. data/lib/card.rb +23 -13
  26. data/lib/card/auth.rb +6 -6
  27. data/lib/card/cache.rb +24 -5
  28. data/lib/card/env.rb +10 -10
  29. data/lib/card/format.rb +29 -12
  30. data/lib/card/log.rb +5 -3
  31. data/lib/card/migration.rb +17 -41
  32. data/lib/card/name.rb +12 -0
  33. data/lib/card/reference.rb +11 -12
  34. data/lib/card/set.rb +59 -6
  35. data/lib/card/simplecov_helper.rb +6 -1
  36. data/lib/card/spec_helper.rb +3 -2
  37. data/lib/card/view_cache.rb +77 -0
  38. data/lib/cardio.rb +30 -22
  39. data/mod/01_core/format/html_format.rb +17 -9
  40. data/mod/01_core/layout/blank.html +1 -1
  41. data/mod/01_core/layout/default.html +6 -16
  42. data/mod/01_core/layout/modal.html +9 -0
  43. data/mod/01_core/layout/noside.html +5 -12
  44. data/mod/01_core/layout/simple.html +1 -1
  45. data/mod/01_core/set/all/collection.rb +57 -5
  46. data/mod/01_core/set/all/content.rb +5 -7
  47. data/mod/01_core/set/all/name.rb +8 -10
  48. data/mod/01_core/set/all/permissions.rb +1 -2
  49. data/mod/01_core/set/all/phases.rb +5 -13
  50. data/mod/01_core/set/all/references.rb +10 -10
  51. data/mod/01_core/set/all/rules.rb +2 -2
  52. data/mod/01_core/set/all/tracked_attributes.rb +5 -3
  53. data/mod/01_core/set/all/utils.rb +79 -9
  54. data/mod/01_core/set/all/view_cache.rb +9 -0
  55. data/mod/01_core/spec/format/html_format_spec.rb +2 -2
  56. data/mod/01_core/spec/set/all/collection_spec.rb +1 -1
  57. data/mod/01_history/lib/card/act.rb +3 -1
  58. data/mod/01_history/lib/card/action.rb +20 -12
  59. data/mod/01_history/lib/card/change.rb +12 -8
  60. data/mod/01_history/set/all/actions.rb +2 -2
  61. data/mod/01_history/set/all/content_history.rb +3 -2
  62. data/mod/01_history/set/all/history.rb +57 -19
  63. data/mod/02_basic_types/set/all/rss.rb +5 -6
  64. data/mod/{05_standard → 02_basic_types}/set/type/html.rb +4 -3
  65. data/mod/02_basic_types/set/type/plain_text.rb +1 -1
  66. data/mod/02_basic_types/set/type/pointer.rb +7 -4
  67. data/mod/02_basic_types/spec/set/type/pointer_spec.rb +21 -17
  68. data/mod/03_machines/lib/card/machine.rb +33 -31
  69. data/mod/03_machines/lib/javascript/script_card_menu.js.coffee +2 -10
  70. data/mod/03_machines/lib/javascript/wagn.js.coffee +10 -10
  71. data/mod/03_machines/lib/javascript/wagn_mod.js.coffee +87 -40
  72. data/mod/03_machines/lib/stylesheets/style_cards.scss +26 -28
  73. data/mod/03_machines/set/right/machine_output.rb +3 -3
  74. data/mod/03_machines/set/type/coffee_script.rb +6 -6
  75. data/mod/03_machines/set/type/css.rb +1 -1
  76. data/mod/03_machines/set/type/java_script.rb +5 -6
  77. data/mod/03_machines/spec/lib/shared_machine_examples.rb +3 -1
  78. data/mod/03_machines/spec/set/type/scss_spec.rb +9 -10
  79. data/mod/04_settings/lib/card/setting.rb +16 -14
  80. data/mod/04_settings/set/right/structure.rb +6 -0
  81. data/mod/04_settings/set/self/add_help.rb +1 -1
  82. data/mod/04_settings/set/self/autoname.rb +1 -1
  83. data/mod/04_settings/set/self/captcha.rb +1 -1
  84. data/mod/04_settings/set/self/default.rb +1 -1
  85. data/mod/04_settings/set/self/help.rb +1 -1
  86. data/mod/04_settings/set/self/input.rb +1 -1
  87. data/mod/04_settings/set/self/layout.rb +1 -1
  88. data/mod/04_settings/set/self/on_create.rb +1 -1
  89. data/mod/04_settings/set/self/on_delete.rb +1 -1
  90. data/mod/04_settings/set/self/on_update.rb +1 -1
  91. data/mod/04_settings/set/self/options.rb +1 -1
  92. data/mod/04_settings/set/self/options_label.rb +1 -1
  93. data/mod/04_settings/set/self/script.rb +1 -1
  94. data/mod/04_settings/set/self/structure.rb +1 -1
  95. data/mod/04_settings/set/self/style.rb +1 -1
  96. data/mod/04_settings/set/self/table_of_contents.rb +1 -1
  97. data/mod/04_settings/set/self/thanks.rb +1 -1
  98. data/mod/05_email/set/all/follow.rb +3 -21
  99. data/mod/05_email/set/all/notify.rb +20 -4
  100. data/mod/05_email/set/right/follow.rb +16 -18
  101. data/mod/05_email/set/self/follow.rb +1 -1
  102. data/mod/05_email/spec/set/all/follow_spec.rb +6 -13
  103. data/mod/05_standard/set/all/attach.rb +23 -9
  104. data/mod/05_standard/set/all/error.rb +5 -7
  105. data/mod/05_standard/set/all/event_viz.rb +10 -6
  106. data/mod/05_standard/set/all/links.rb +37 -13
  107. data/mod/05_standard/set/all/rich_html/content.rb +46 -18
  108. data/mod/05_standard/set/all/rich_html/editing.rb +29 -25
  109. data/mod/05_standard/set/all/rich_html/form.rb +17 -10
  110. data/mod/05_standard/set/all/rich_html/header.rb +26 -4
  111. data/mod/05_standard/set/all/rich_html/menu.rb +17 -34
  112. data/mod/05_standard/set/all/rich_html/modal.rb +50 -12
  113. data/mod/05_standard/set/all/rich_html/toolbar.rb +178 -186
  114. data/mod/05_standard/set/all/rich_html/wrapper.rb +44 -21
  115. data/mod/05_standard/set/rstar/rules.rb +43 -53
  116. data/mod/05_standard/set/self/all.rb +2 -1
  117. data/mod/05_standard/set/self/head.rb +2 -2
  118. data/mod/05_standard/set/self/signin.rb +18 -18
  119. data/mod/05_standard/set/self/stats.rb +14 -2
  120. data/mod/05_standard/set/type/search_type.rb +9 -4
  121. data/mod/05_standard/set/type/session.rb +12 -7
  122. data/mod/05_standard/set/type/set.rb +135 -18
  123. data/mod/05_standard/spec/chunk/include_spec.rb +15 -16
  124. data/mod/05_standard/spec/set/all/account_spec.rb +21 -21
  125. data/mod/05_standard/spec/set/all/event_viz_spec.rb +7 -7
  126. data/mod/05_standard/spec/set/all/history_spec.rb +54 -24
  127. data/mod/05_standard/spec/set/all/rich_html/editing_spec.rb +42 -40
  128. data/mod/05_standard/spec/set/rstar/rules_spec.rb +1 -1
  129. data/mod/05_standard/spec/set/type/search_type_spec.rb +9 -1
  130. data/mod/05_standard/spec/set/type/signup_spec.rb +42 -42
  131. data/mod/06_bootstrap/lib/stylesheets/bootstrap_cards.scss +6 -0
  132. data/mod/06_bootstrap/set/all/bootstrap/form.rb +4 -5
  133. data/mod/06_bootstrap/set/all/bootstrap/helper.rb +145 -0
  134. data/mod/06_bootstrap/set/all/rich_bootstrap.rb +0 -59
  135. data/spec/lib/card/action_spec.rb +1 -1
  136. data/spec/lib/card/log_spec.rb +7 -7
  137. data/spec/models/card/cardtype_spec.rb +1 -1
  138. data/spec/spec_helper.rb +1 -1
  139. metadata +31 -6
  140. data/mod/04_settings/set/self/comment.rb +0 -2
@@ -0,0 +1 @@
1
+ file1
@@ -0,0 +1 @@
1
+ file2
@@ -1 +1 @@
1
- 20150528084659
1
+ 20150702130543
data/lib/card.rb CHANGED
@@ -3,6 +3,14 @@
3
3
  Object.send :remove_const, :Card if Object.send(:const_defined?, :Card)
4
4
 
5
5
  class Card < ActiveRecord::Base
6
+
7
+ # attributes that ActiveJob can handle
8
+ def self.serializable_attr_accessor *args
9
+ self.serializable_attributes = args
10
+ attr_accessor *args
11
+ end
12
+
13
+
6
14
  require_dependency 'card/active_record_ext'
7
15
  require_dependency 'card/codename'
8
16
  require_dependency 'card/query'
@@ -19,30 +27,32 @@ class Card < ActiveRecord::Base
19
27
 
20
28
  has_many :references_from, :class_name => :Reference, :foreign_key => :referee_id
21
29
  has_many :references_to, :class_name => :Reference, :foreign_key => :referer_id
22
- has_many :acts, :order => :id
23
- has_many :actions, :order => :id, :conditions=>{:draft => [nil,false]}
24
- has_many :drafts, :order=>:id, :conditions=>{:draft=>true}, :class_name=> :Action
30
+ has_many :acts, -> { order :id }
31
+ has_many :actions, -> { where( :draft=>[nil,false]).order :id }
32
+ has_many :drafts, -> { where( :draft=>true ).order :id }, :class_name=> :Action
25
33
 
26
- cache_attributes 'name', 'type_id' # review - still worth it in Rails 3?
27
-
28
- cattr_accessor :set_patterns, :error_codes
34
+ cattr_accessor :set_patterns, :error_codes, :serializable_attributes
29
35
  @@set_patterns, @@error_codes = [], {}
30
36
 
31
- attr_accessor :action, :supercard, :current_act, :current_action,
37
+ serializable_attr_accessor :action, :supercard, :current_act, :current_action,
32
38
  :comment, :comment_author, # obviated soon
33
39
  :update_referencers, # wrong mechanism for this
34
- :update_all_users, # if the above is wrong then this one too
35
- :follower_stash, :remove_rule_stash,
40
+ :update_all_users, # if the above is wrong then this one too
41
+ :remove_rule_stash,
36
42
  :last_action_id_before_edit
37
-
38
- define_callbacks :approve, :store, :extend
39
-
43
+
44
+ attr_accessor :follower_stash
45
+
46
+ define_callbacks :approve, :store, :stored, :extend, :subsequent
47
+
40
48
  before_validation :approve
41
49
  around_save :store
42
50
  after_save :extend
43
-
51
+
52
+
44
53
  TRACKED_FIELDS = %w(name type_id db_content trash)
45
54
 
46
55
  ActiveSupport.run_load_hooks(:card, self)
47
56
  end
48
57
 
58
+
data/lib/card/auth.rb CHANGED
@@ -11,7 +11,7 @@ class Card
11
11
 
12
12
  class << self
13
13
 
14
- # Authenticates a user by their login name and unencrypted password.
14
+ # Authenticates a user by their login name and unencrypted password.
15
15
  def authenticate email, password
16
16
  accounted = Auth[ email ]
17
17
  if accounted and account = accounted.account and account.active?
@@ -40,7 +40,7 @@ class Card
40
40
  ]).first
41
41
  end
42
42
  end
43
-
43
+
44
44
  def signin signin_id
45
45
  self.current_id = signin_id
46
46
  session[:user] = signin_id if session
@@ -51,7 +51,7 @@ class Card
51
51
  end
52
52
 
53
53
  def set_current_from_session
54
- self.current_id =
54
+ self.current_id =
55
55
  if session
56
56
  if card_id=session[:user] and Card.exists? card_id
57
57
  card_id
@@ -135,12 +135,12 @@ class Card
135
135
  @@simulating_setup_need or Card.cache.write( NEED_SETUP_KEY, (account_count < 3) ) # 3, because
136
136
  end
137
137
  end
138
-
138
+
139
139
  def simulate_setup_need! mode=true
140
140
  @@simulating_setup_need = mode
141
141
  Card.cache.write NEED_SETUP_KEY, nil
142
142
  end
143
-
143
+
144
144
 
145
145
  def always_ok?
146
146
  #warn Rails.logger.warn("aok? #{as_id}, #{as_id&&Card[as_id].id}")
@@ -171,7 +171,7 @@ class Card
171
171
  end
172
172
 
173
173
  private
174
-
174
+
175
175
  def account_count
176
176
  as_bot { Card.count_by_wql :right=>Card[:account].name }
177
177
  end
data/lib/card/cache.rb CHANGED
@@ -73,6 +73,21 @@ class Card
73
73
  end
74
74
  end
75
75
 
76
+ def obj_to_key obj
77
+ case obj
78
+ when Hash
79
+ obj.sort.map do |key, value|
80
+ "#{key}=>(#{obj_to_key(value)})"
81
+ end.join ","
82
+ when Array
83
+ obj.map do |value|
84
+ obj_to_key(value)
85
+ end.join ","
86
+ else
87
+ obj.to_s
88
+ end
89
+ end
90
+
76
91
  private
77
92
 
78
93
  def prepopulate
@@ -103,7 +118,7 @@ class Card
103
118
  self.system_prefix = opts[:prefix] || self.class.system_prefix(opts[:class])
104
119
  cache_by_class[klass] = self
105
120
  end
106
-
121
+
107
122
 
108
123
  def system_prefix= system_prefix
109
124
  @system_prefix = system_prefix
@@ -125,11 +140,11 @@ class Card
125
140
  write_local key, @store.read(@prefix + key)
126
141
  end
127
142
  end
128
-
143
+
129
144
  def read_local key
130
145
  @local[key]
131
146
  end
132
-
147
+
133
148
  def write_variable key, variable, value
134
149
  key = @prefix + key
135
150
  if @store and object = @store.read(key)
@@ -157,7 +172,7 @@ class Card
157
172
  end
158
173
  end
159
174
  end
160
-
175
+
161
176
  def fetch_local key
162
177
  read_local key or write_local key, yield
163
178
  end
@@ -190,10 +205,14 @@ class Card
190
205
  end
191
206
  @prefix = @system_prefix + @cache_id + "/"
192
207
  end
193
-
208
+
194
209
  def reset_local
195
210
  @local = {}
196
211
  end
212
+
213
+ def exist? key
214
+ @local.has_key?(key) || @store.exist?(key)
215
+ end
197
216
  end
198
217
  end
199
218
 
data/lib/card/env.rb CHANGED
@@ -5,40 +5,40 @@ class Card
5
5
  class << self
6
6
  def reset args={}
7
7
  @@env = { :main_name => nil }
8
-
8
+
9
9
  if c = args[:controller]
10
10
  self[:controller] = c
11
11
  self[:session] = c.request.session
12
- self[:params] = c.request.params
12
+ self[:params] = c.params
13
13
  self[:ip] = c.request.remote_ip
14
14
  self[:ajax] = c.request.xhr? || c.request.params[:simulate_xhr]
15
15
  self[:host] = Card.config.override_host || c.request.env['HTTP_HOST']
16
16
  self[:protocol] = Card.config.override_protocol || c.request.protocol
17
-
17
+
18
18
  end
19
19
  end
20
-
20
+
21
21
  def [] key
22
22
  @@env[key.to_sym]
23
23
  end
24
-
24
+
25
25
  def []= key, value
26
26
  @@env[key.to_sym] = value
27
27
  end
28
-
28
+
29
29
 
30
30
  def params
31
31
  self[:params] ||= {}
32
32
  end
33
-
33
+
34
34
  def session
35
35
  self[:session] ||= {}
36
36
  end
37
-
37
+
38
38
  def ajax?
39
39
  self[:ajax]
40
40
  end
41
-
41
+
42
42
  def method_missing method_id, *args
43
43
  case args.length
44
44
  when 0 ; self[ method_id ]
@@ -47,6 +47,6 @@ class Card
47
47
  end
48
48
  end
49
49
  end
50
- end
50
+ end
51
51
  Env.reset
52
52
  end
data/lib/card/format.rb CHANGED
@@ -146,6 +146,14 @@ class Card
146
146
  end
147
147
  end
148
148
 
149
+ def with_name_context name
150
+ old_context = @context_names
151
+ add_name_context name
152
+ result = yield
153
+ @context_names = old_context
154
+ result
155
+ end
156
+
149
157
  def main?
150
158
  @depth == 0
151
159
  end
@@ -197,7 +205,9 @@ class Card
197
205
  args = default_render_args view, args
198
206
  with_inclusion_mode view do
199
207
  Card.with_logging :view, :message=>view, :context=>card.name, :details=>args do
200
- send "_view_#{ view }", args
208
+ Card::ViewCache.fetch(self, view, args) do
209
+ send "_view_#{ view }", args
210
+ end
201
211
  end
202
212
  end
203
213
  end
@@ -267,7 +277,11 @@ class Card
267
277
  Rails.logger.info "\nError rendering #{error_cardname} / #{view}: #{e.class} : #{e.message}"
268
278
  Card::Error.current = e
269
279
  card.notable_exception_raised
270
- rendering_error e, view
280
+ if (debug = Card[:debugger]) && debug.content == 'on'
281
+ raise e
282
+ else
283
+ rendering_error e, view
284
+ end
271
285
  end
272
286
  end
273
287
 
@@ -387,15 +401,17 @@ class Card
387
401
 
388
402
  def prepare_nest opts
389
403
  @char_count ||= 0
390
-
391
404
  opts ||= {}
405
+
392
406
  case
393
- when opts.has_key?( :comment ) ; opts[:comment] # as in commented code
394
- when @mode == :closed && @char_count > Card.config.max_char_count ; '' # already out of view
395
- when opts[:inc_name]=='_main' && !Env.ajax? && @depth==0 ; expand_main opts
396
- else
397
- nested_card = Card.fetch opts[:inc_name], :new=>new_inclusion_card_args(opts)
398
- result = nest nested_card, opts
407
+ when opts.has_key?(:comment) # commented nest
408
+ opts[:comment]
409
+ when @mode == :closed && @char_count > Card.config.max_char_count # move on; content out of view
410
+ ''
411
+ when opts[:inc_name] == '_main' && show_layout? && @depth==0 # the main card within a layout
412
+ expand_main opts
413
+ else # standard nest
414
+ result = nest fetch_nested_card(opts), opts
399
415
  @char_count += result.length if @mode == :closed && result
400
416
  result
401
417
  end
@@ -462,7 +478,8 @@ class Card
462
478
  else
463
479
  view
464
480
  end
465
- sub.render view, opts
481
+
482
+ sub.optional_render view, opts
466
483
  #end
467
484
  end
468
485
 
@@ -477,7 +494,7 @@ class Card
477
494
  # probably for blanks? -- older/wiser efm
478
495
  end
479
496
 
480
- def new_inclusion_card_args options
497
+ def fetch_nested_card options
481
498
  args = { :name=>options[:inc_name], :type=>options[:type], :supercard=>card }
482
499
  args.delete(:supercard) if options[:inc_name].strip.blank? # special case. gets absolutized incorrectly. fix in smartname?
483
500
  if options[:inc_name] =~ /^_main\+/
@@ -488,7 +505,7 @@ class Card
488
505
  if content=get_inclusion_content(options[:inc_name])
489
506
  args[:content]=content
490
507
  end
491
- args
508
+ Card.fetch options[:inc_name], :new=>args
492
509
  end
493
510
 
494
511
  def default_item_view
data/lib/card/log.rb CHANGED
@@ -38,8 +38,7 @@ class Card::Log
38
38
 
39
39
 
40
40
  class Performance
41
- # To enable logging add a performance_logger hash to your configuration and change the log_level to :wagn
42
- # config options
41
+ # To enable logging add a performance_logger hash to your configuration
43
42
  #
44
43
  # Example:
45
44
  # config.performance_logger = {
@@ -47,6 +46,7 @@ class Card::Log
47
46
  # :max_depth => 3, # show nested method calls only up to depth 3
48
47
  # :details=> true, # show method arguments and sql
49
48
  # :methods => [:event, :search, :fetch, :view], # choose methods to log
49
+ # :log_level => :info
50
50
  # }
51
51
  #
52
52
  # If you give :methods a hash you can log arbitrary methods. The syntax is as follows:
@@ -71,6 +71,7 @@ class Card::Log
71
71
 
72
72
  DEFAULT_CLASS = Card
73
73
  DEFAULT_METHOD_TYPE = :all
74
+ DEFAULT_LOG_LEVEL = :info
74
75
  DEFAULT_METHOD_OPTIONS = {
75
76
  :title => :method_name,
76
77
  :message => 1,
@@ -111,6 +112,7 @@ class Card::Log
111
112
  @details = args[:details] || false
112
113
  @max_depth = args[:max_depth] || false
113
114
  @min_time = args[:min_time] || false
115
+ @log_level = args[:log_level] || DEFAULT_LOG_LEVEL
114
116
  @output = args[:output] || :text
115
117
  @enabled_methods = ::Set.new
116
118
  prepare_methods_for_logging args[:methods] if args[:methods]
@@ -194,7 +196,7 @@ class Card::Log
194
196
 
195
197
  def text_log
196
198
  @@log.each do |entry|
197
- Rails.logger.wagn entry.to_s! if entry.valid
199
+ Rails.logger.send @log_level, entry.to_s! if entry.valid
198
200
  end
199
201
  end
200
202
 
@@ -1,5 +1,5 @@
1
1
  # -*- encoding : utf-8 -*-
2
-
2
+
3
3
  class Card::Migration < ActiveRecord::Migration
4
4
  @type = :deck_cards
5
5
 
@@ -42,8 +42,10 @@ class Card::Migration < ActiveRecord::Migration
42
42
  original_suffix = ActiveRecord::Base.table_name_suffix
43
43
 
44
44
  ActiveRecord::Base.table_name_suffix = new_suffix
45
+ ActiveRecord::SchemaMigration.reset_table_name
45
46
  yield
46
47
  ActiveRecord::Base.table_name_suffix = original_suffix
48
+ ActiveRecord::SchemaMigration.reset_table_name
47
49
  end
48
50
 
49
51
  def assume_migrated_upto_version
@@ -51,12 +53,12 @@ class Card::Migration < ActiveRecord::Migration
51
53
  ActiveRecord::Schema.assume_migrated_upto_version schema, migration_paths
52
54
  end
53
55
  end
54
-
56
+
55
57
  def data_path filename=nil
56
58
  path = migration_paths.first
57
59
  File.join( [ migration_paths.first, 'data', filename ].compact )
58
60
  end
59
-
61
+
60
62
  end
61
63
 
62
64
  def contentedly &block
@@ -79,7 +81,7 @@ class Card::Migration < ActiveRecord::Migration
79
81
  merge_opts.reverse_merge! :output_file=>File.join(data_path,"unmerged_#{ filename }")
80
82
  Card.merge_list read_json(filename), merge_opts
81
83
  end
82
-
84
+
83
85
  def read_json filename
84
86
  raw_json = File.read( data_path filename )
85
87
  json = JSON.parse raw_json
@@ -98,50 +100,24 @@ class Card::Migration < ActiveRecord::Migration
98
100
  Cardio.paths self.class.type
99
101
  end
100
102
 
101
-
102
103
  # Execute this migration in the named direction
103
104
  # copied from ActiveRecord to wrap "up" in "contentendly"
104
- def migrate(direction)
105
- return unless respond_to?(direction)
106
-
107
- case direction
108
- when :up then announce "migrating"
109
- when :down then announce "reverting"
110
- end
111
-
112
- time = nil
113
- ActiveRecord::Base.connection_pool.with_connection do |conn|
114
- @connection = conn
115
- if respond_to?(:change)
116
- if direction == :down
117
- recorder = CommandRecorder.new(@connection)
118
- suppress_messages do
119
- @connection = recorder
120
- change
121
- end
122
- @connection = conn
123
- time = Benchmark.measure {
124
- self.revert {
125
- recorder.inverse.each do |cmd, args|
126
- send(cmd, *args)
127
- end
128
- }
129
- }
130
- else
131
- time = Benchmark.measure { change }
132
- end
105
+ def exec_migration(conn, direction)
106
+ @connection = conn
107
+ if respond_to?(:change)
108
+ if direction == :down
109
+ revert { change }
133
110
  else
134
- time = Benchmark.measure { contentedly { send(direction) } }
111
+ change
135
112
  end
136
- @connection = nil
137
- end
138
-
139
- case direction
140
- when :up then announce "migrated (%.4fs)" % time.real; write
141
- when :down then announce "reverted (%.4fs)" % time.real; write
113
+ else
114
+ contentedly { send(direction) }
142
115
  end
116
+ ensure
117
+ @connection = nil
143
118
  end
144
119
 
120
+
145
121
  def down
146
122
  raise ActiveRecord::IrreversibleMigration
147
123
  end