Class: SidekiqUniqueJobs::Script::Script

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_unique_jobs/script/script.rb

Overview

Interface to dealing with .lua files

Author:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, root_path:) ⇒ Script

Returns a new instance of Script.



39
40
41
42
43
44
45
46
# 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

Instance Attribute Details

#call_countObject

Returns the value of attribute call_count.



37
38
39
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 37

def call_count
  @call_count
end

#nameObject (readonly)

Returns the value of attribute name.



17
18
19
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 17

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



21
22
23
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 21

def path
  @path
end

#root_pathObject (readonly)

Returns the value of attribute root_path.



25
26
27
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 25

def root_path
  @root_path
end

#script_nameSymbol, String (readonly)

Returns the name of the script without extension.

Returns:

  • (Symbol, String)

    the name of the script without extension



17
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 17

attr_reader :name

#script_pathString (readonly)

Returns the path to the script on disk.

Returns:

  • (String)

    the path to the script on disk



21
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 21

attr_reader :path

#shaObject

Returns the value of attribute sha.



33
34
35
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 33

def sha
  @sha
end

#sourceObject (readonly)

Returns the value of attribute source.



29
30
31
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 29

def source
  @source
end

Class Method Details

.load(name, root_path, conn) ⇒ Object



9
10
11
12
# 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

Instance Method Details

#==(other) ⇒ Object



48
49
50
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 48

def ==(other)
  sha == compiled_sha && compiled_sha == other.sha
end

#changed?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 56

def changed?
  compiled_sha != sha
end

#compiled_shaObject



64
65
66
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 64

def compiled_sha
  Digest::SHA1.hexdigest(source)
end

#increment_call_countObject



52
53
54
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 52

def increment_call_count
  @call_count += 1
end

#load(conn) ⇒ Object



68
69
70
71
72
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 68

def load(conn)
  @sha = conn.script(:load, source)

  self
end

#render_fileObject



60
61
62
# File 'lib/sidekiq_unique_jobs/script/script.rb', line 60

def render_file
  Template.new(root_path).render(path)
end