Module: Card::Set::Abstract::Machine::OutputUpdate

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod016-card-mod-machines/abstract/machine/output_update.rb,
card/tmpsets/set/mod015-card-mod-machines/abstract/machine/output_update.rb

Overview

Set: Abstract (Machine, OutputUpdate)

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



7
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine/output_update.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card-mod-machines/set/abstract/machine/output_update.rb"; end

Instance Method Details

#ensure_machine_outputObject



32
33
34
35
36
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine/output_update.rb', line 32

def ensure_machine_output
  output = fetch :machine_output
  return if output&.selected_content_action_id
  update_machine_output
end

#expire_if_source_file_changed(output_updated_at) ⇒ Object



54
55
56
57
58
59
60
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine/output_update.rb', line 54

def expire_if_source_file_changed output_updated_at
  return unless output_updated_at
  changed = input_cards_with_changed_source(output_updated_at)
  return if changed.empty?
  changed.each(&:expire_machine_cache)
  true
end

#input_cards_with_changed_source(output_updated) ⇒ Object



48
49
50
51
52
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine/output_update.rb', line 48

def input_cards_with_changed_source output_updated
  machine_input_card.extended_item_cards.select do |i_card|
    i_card.try(:source_changed?, since: output_updated)
  end
end

#output_updated_atObject



68
69
70
71
72
73
74
75
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine/output_update.rb', line 68

def output_updated_at
  return unless (output_card = machine_output_card)
  if output_card.coded?
    File.mtime output_card.file.path
  else
    output_card.updated_at
  end
end

#regenerate_machine_outputObject



18
19
20
21
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine/output_update.rb', line 18

def regenerate_machine_output
  return unless ok?(:read)
  lock { run_machine }
end

#reset_machine_outputObject



8
9
10
11
12
13
14
15
16
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine/output_update.rb', line 8

def reset_machine_output
  Auth.as_bot do
    moc = machine_output_card
    @updated_at = output_updated_at
    moc.delete! if moc.real?
    update_input_card
    expire_if_source_file_changed @updated_at
  end
end

#update_if_source_file_changedObject

regenerates the machine output if a source file of a input card has been changed



63
64
65
66
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine/output_update.rb', line 63

def update_if_source_file_changed
  return unless expire_if_source_file_changed output_updated_at
  regenerate_machine_output
end

#update_input_cardObject



38
39
40
41
42
43
44
45
46
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine/output_update.rb', line 38

def update_input_card
  if Card::Director.running_act?
    input_card = attach_subcard! machine_input_card
    input_card.content = ""
    engine_input.each { |input| input_card << input }
  else
    machine_input_card.items = engine_input
  end
end

#update_machine_outputObject



23
24
25
26
27
28
29
30
# File 'card/tmpsets/set/mod016-card-mod-machines/abstract/machine/output_update.rb', line 23

def update_machine_output
  return unless ok?(:read)
  lock do
    update_input_card
    expire_if_source_file_changed output_updated_at
    run_machine
  end
end