Class: Brpoplpush::RedisScript::Script
- Inherits:
-
Object
- Object
- Brpoplpush::RedisScript::Script
- Defined in:
- lib/brpoplpush/redis_script/script.rb
Overview
Interface to dealing with .lua files
Instance Attribute Summary collapse
-
#call_count ⇒ Object
Returns the value of attribute call_count.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
-
#script_name ⇒ Symbol, String
readonly
The name of the script without extension.
-
#script_path ⇒ String
readonly
The path to the script on disk.
-
#sha ⇒ Object
Returns the value of attribute sha.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #changed? ⇒ Boolean
- #compiled_sha ⇒ Object
- #increment_call_count ⇒ Object
-
#initialize(name:, root_path:) ⇒ Script
constructor
A new instance of Script.
- #load(conn) ⇒ Object
- #render_file ⇒ Object
Constructor Details
#initialize(name:, root_path:) ⇒ Script
Returns a new instance of Script.
39 40 41 42 43 44 45 46 |
# File 'lib/brpoplpush/redis_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_count ⇒ Object
Returns the value of attribute call_count.
37 38 39 |
# File 'lib/brpoplpush/redis_script/script.rb', line 37 def call_count @call_count end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/brpoplpush/redis_script/script.rb', line 17 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
21 22 23 |
# File 'lib/brpoplpush/redis_script/script.rb', line 21 def path @path end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
25 26 27 |
# File 'lib/brpoplpush/redis_script/script.rb', line 25 def root_path @root_path end |
#script_name ⇒ Symbol, String (readonly)
Returns the name of the script without extension.
17 |
# File 'lib/brpoplpush/redis_script/script.rb', line 17 attr_reader :name |
#script_path ⇒ String (readonly)
Returns the path to the script on disk.
21 |
# File 'lib/brpoplpush/redis_script/script.rb', line 21 attr_reader :path |
#sha ⇒ Object
Returns the value of attribute sha.
33 34 35 |
# File 'lib/brpoplpush/redis_script/script.rb', line 33 def sha @sha end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
29 30 31 |
# File 'lib/brpoplpush/redis_script/script.rb', line 29 def source @source end |
Class Method Details
.load(name, root_path, conn) ⇒ Object
9 10 11 12 |
# File 'lib/brpoplpush/redis_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/brpoplpush/redis_script/script.rb', line 48 def ==(other) sha == compiled_sha && compiled_sha == other.sha end |
#changed? ⇒ Boolean
56 57 58 |
# File 'lib/brpoplpush/redis_script/script.rb', line 56 def changed? compiled_sha != sha end |
#compiled_sha ⇒ Object
64 65 66 |
# File 'lib/brpoplpush/redis_script/script.rb', line 64 def compiled_sha Digest::SHA1.hexdigest(source) end |
#increment_call_count ⇒ Object
52 53 54 |
# File 'lib/brpoplpush/redis_script/script.rb', line 52 def increment_call_count @call_count += 1 end |
#load(conn) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/brpoplpush/redis_script/script.rb', line 68 def load(conn) @sha = if conn.respond_to?(:namespace) conn.redis.script(:load, source) else conn.script(:load, source) end self end |