mod/machines/lib/card/machine.rb in card-1.94.1 vs mod/machines/lib/card/machine.rb in card-1.95.0
- old
+ new
@@ -3,63 +3,31 @@
REFRESHED="MACHINE_ASSETS_REFRESHED".freeze
class << self
def refresh_script_and_style
return unless refresh_script_and_style?
- update_if_source_file_changed Card[:all, :script]
- update_if_source_file_changed Card[:all, :style]
+ Card.fetch(:all, :script)&.update_if_source_file_changed
+ Card.fetch(:all, :style)&.update_if_source_file_changed
end
private
def refresh_script_and_style?
- Cardio.config.eager_machine_refresh || cautious_refresh?
+ case Cardio.config.machine_refresh
+ when :eager then true
+ when :cautious then cautious_refresh?
+ when :never then false
+ else
+ raise Card::Error,
+ "unknown option for machine_refresh: #{Cardio.config.machine_refresh}"
+ end
end
+ # only refresh when cache was cleared
def cautious_refresh?
return false unless Card::Cache.persistent_cache
return false if Card.cache.read REFRESHED
Card.cache.write REFRESHED, true
- end
-
- # regenerates the machine output if a source file of a input card
- # has been changed
- def update_if_source_file_changed machine_card
- return unless (output_updated = output_last_updated(machine_card))
- input_cards_with_source_files(machine_card) do |i_card, files|
- files.each do |path|
- next unless File.mtime(path) > output_updated
- i_card.expire_machine_cache
- return machine_card.regenerate_machine_output
- end
- end
- end
-
- def output_last_updated machine_card
- return unless (output_card = machine_card&.machine_output_card)
- if output_card.coded?
- File.mtime output_card.file.path
- else
- output_card.updated_at
- end
- end
-
- def input_cards_with_source_files card
- card.machine_input_card.extended_item_cards.each do |i_card|
- next unless i_card.codename
- next unless i_card.respond_to?(:existing_source_paths)
- yield i_card, i_card.existing_source_paths
- end
- end
-
- def source_files card
- files = []
- card.machine_input_card.extended_item_cards.each do |i_card|
- next unless i_card.codename
- next unless i_card.respond_to?(:existing_source_paths)
- files << i_card.existing_source_paths
- end
- files.flatten
end
end
end
end