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
Returns a new instance of QueueHook.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/furaffinity/queue_hook.rb', line 37 def initialize(client, file_info) @client = client @file_info = file_info.each_with_object({}) do |(file_name, info), h| # 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. h[file_name] = info.except(:create_folder_name, :after_upload, :type) end end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
35 36 37 |
# File 'lib/furaffinity/queue_hook.rb', line 35 def client @client end |
#file_info ⇒ Object (readonly)
Returns the value of attribute file_info.
35 36 37 |
# File 'lib/furaffinity/queue_hook.rb', line 35 def file_info @file_info end |
Instance Method Details
#run_hook(file_name, code) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/furaffinity/queue_hook.rb', line 57 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
48 49 50 51 52 53 54 55 |
# File 'lib/furaffinity/queue_hook.rb', line 48 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 |