class SidekiqUniqueJobs::Script::Script
Interface to dealing with .lua files
@author Mikael Henriksson <mikael@mhenrixon.com>
Attributes
@!attribute [rw] call_count
@return [Integer] the number of times the script was called/executed
@!attribute [r] script_name
@return [Symbol, String] the name of the script without extension
@!attribute [r] script_path
@return [String] the path to the script on disk
@!attribute [r] root_path
@return [Pathname]
@!attribute [rw] sha
@return [String] the sha of the script
@!attribute [r] source
@return [String] the source code of the lua script
Public Class Methods
Source
# File lib/sidekiq_unique_jobs/script/script.rb, line 9 def self.load(name, root_path, conn) script = new(name: name, root_path: root_path) script.load(conn) end
Source
# File lib/sidekiq_unique_jobs/script/script.rb, line 39 def initialize(name:, root_path:) @name = name @root_path = root_path @path = root_path.join("#{name}.lua").to_s @source = render_file @sha = compiled_sha @call_count = 0 end
Public Instance Methods
Source
# File lib/sidekiq_unique_jobs/script/script.rb, line 48 def ==(other) sha == compiled_sha && compiled_sha == other.sha end
Source
# File lib/sidekiq_unique_jobs/script/script.rb, line 56 def changed? compiled_sha != sha end
Source
# File lib/sidekiq_unique_jobs/script/script.rb, line 64 def compiled_sha Digest::SHA1.hexdigest(source) end
Source
# File lib/sidekiq_unique_jobs/script/script.rb, line 52 def increment_call_count @call_count += 1 end
Source
# File lib/sidekiq_unique_jobs/script/script.rb, line 68 def load(conn) @sha = conn.script(:load, source) self end
Source
# File lib/sidekiq_unique_jobs/script/script.rb, line 60 def render_file Template.new(root_path).render(path) end