Class: SaferRedis::CommandDoc
- Inherits:
-
Object
- Object
- SaferRedis::CommandDoc
- Defined in:
- lib/safer_redis/command_doc.rb
Constant Summary collapse
- CATEGORY_SLOW =
"@slow"
- CATEGORY_DANGEROUS =
"@dangerous"
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.commands_data ⇒ Object
JSON-parsed Redis command data from the embedded copy of github.com/redis/redis-doc/blob/master/commands.json.
-
.from_command_array(a) ⇒ Object
The ‘redis` gem represents commands internally as an array with the command name as a lower-case symbol as the first item, e.g.
Instance Method Summary collapse
- #acl_categories ⇒ Object
- #complexity ⇒ Object
- #dangerous? ⇒ Boolean
-
#initialize(name) ⇒ CommandDoc
constructor
A new instance of CommandDoc.
- #slow? ⇒ Boolean
- #suggestion ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(name) ⇒ CommandDoc
Returns a new instance of CommandDoc.
27 28 29 |
# File 'lib/safer_redis/command_doc.rb', line 27 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
31 32 33 |
# File 'lib/safer_redis/command_doc.rb', line 31 def name @name end |
Class Method Details
.commands_data ⇒ Object
JSON-parsed Redis command data from the embedded copy of github.com/redis/redis-doc/blob/master/commands.json
12 13 14 15 16 17 18 19 |
# File 'lib/safer_redis/command_doc.rb', line 12 def self.commands_data @commands_data ||= begin base_dir = File.absolute_path(File.join(__dir__, "..", "..")) path = File.join(base_dir, "data", "redis-doc", "commands.json") JSON.parse(File.read(path)) end end |
.from_command_array(a) ⇒ Object
The ‘redis` gem represents commands internally as an array with the command name as a lower-case symbol as the first item, e.g. [:del, “foo”, “bar”]
23 24 25 |
# File 'lib/safer_redis/command_doc.rb', line 23 def self.from_command_array(a) new(a.first.to_s.upcase) end |
Instance Method Details
#acl_categories ⇒ Object
47 48 49 |
# File 'lib/safer_redis/command_doc.rb', line 47 def acl_categories command.fetch("acl_categories", []) end |
#complexity ⇒ Object
51 52 53 |
# File 'lib/safer_redis/command_doc.rb', line 51 def complexity command.fetch("complexity", nil) end |
#dangerous? ⇒ Boolean
43 44 45 |
# File 'lib/safer_redis/command_doc.rb', line 43 def dangerous? acl_categories.include?(CATEGORY_DANGEROUS) end |
#slow? ⇒ Boolean
39 40 41 |
# File 'lib/safer_redis/command_doc.rb', line 39 def slow? acl_categories.include?(CATEGORY_SLOW) end |
#suggestion ⇒ Object
55 56 57 |
# File 'lib/safer_redis/command_doc.rb', line 55 def suggestion Suggestion.for_command(name) end |
#url ⇒ Object
33 34 35 36 37 |
# File 'lib/safer_redis/command_doc.rb', line 33 def url slug = name.downcase.gsub(" ", "-") "https://redis.io/commands/#{slug}/" end |