Class: SaferRedis::CommandDoc

Inherits:
Object
  • Object
show all
Defined in:
lib/safer_redis/command_doc.rb

Constant Summary collapse

CATEGORY_SLOW =
"@slow"
CATEGORY_DANGEROUS =
"@dangerous"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (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_dataObject

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_categoriesObject



47
48
49
# File 'lib/safer_redis/command_doc.rb', line 47

def acl_categories
  command.fetch("acl_categories", [])
end

#complexityObject



51
52
53
# File 'lib/safer_redis/command_doc.rb', line 51

def complexity
  command.fetch("complexity", nil)
end

#dangerous?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/safer_redis/command_doc.rb', line 43

def dangerous?
  acl_categories.include?(CATEGORY_DANGEROUS)
end

#slow?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/safer_redis/command_doc.rb', line 39

def slow?
  acl_categories.include?(CATEGORY_SLOW)
end

#suggestionObject



55
56
57
# File 'lib/safer_redis/command_doc.rb', line 55

def suggestion
  Suggestion.for_command(name)
end

#urlObject



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