Class: Furaffinity::QueueHook
- Inherits:
-
Object
- Object
- Furaffinity::QueueHook
- Includes:
- SemanticLogger::Loggable
- Defined in:
- lib/furaffinity/queue_hook.rb
Defined Under Namespace
Classes: HookRunner
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#file_info ⇒ Object
readonly
Returns the value of attribute file_info.
Instance Method Summary collapse
-
#initialize(client, file_info) ⇒ QueueHook
constructor
A new instance of QueueHook.
- #run_hook(file_name, code) ⇒ Object
- #update_ids(upload_status) ⇒ Object
Constructor Details
#initialize(client, file_info) ⇒ QueueHook
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/furaffinity/queue_hook.rb', line 39 def initialize(client, file_info) @client = client @file_info = file_info.transform_values do |info| # Hash#except duplicates the hash, which is good here as we don't want # to modify the queue. # exclude after_upload as it's not needed, and create_folder_name and # type is only relevant when initially uploading the submission. info.except(:create_folder_name, :after_upload, :type) end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
37 38 39 |
# File 'lib/furaffinity/queue_hook.rb', line 37 def client @client end |
#file_info ⇒ Object (readonly)
Returns the value of attribute file_info.
37 38 39 |
# File 'lib/furaffinity/queue_hook.rb', line 37 def file_info @file_info end |
Instance Method Details
#run_hook(file_name, code) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/furaffinity/queue_hook.rb', line 59 def run_hook(file_name, code) logger.debug { "Running hook" } logger.trace { "Hook code:\n#{code}" } HookRunner .new(client, file_info, file_name) .instance_eval(code, File.join(Dir.pwd, "#{file_name}.info.yml"), 0) end |
#update_ids(upload_status) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/furaffinity/queue_hook.rb', line 50 def update_ids(upload_status) logger.trace { "Updating file info ids" } upload_status.each do |file_name, status| next unless status[:uploaded] @file_info[file_name][:id] = status[:url].match(%{/view/(?<id>[^/]+)})[:id] end end |