Class: RailsOpenapiGen::Parsers::Jbuilder::CallDetectors::CacheCallDetector

Inherits:
BaseDetector
  • Object
show all
Defined in:
lib/rails-openapi-gen/parsers/jbuilder/call_detectors/cache_call_detector.rb

Overview

Detects cache calls (json.cache!, json.cache_if!) Handles caching directives in Jbuilder templates

Constant Summary collapse

CACHE_METHODS =

Cache methods that this detector handles

%w[cache! cache_if!].freeze

Class Method Summary collapse

Class Method Details

.cache_call?(receiver, method_name) ⇒ Boolean

Check if this is a cache call



42
43
44
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/cache_call_detector.rb', line 42

def cache_call?(receiver, method_name)
  method_name == :cache! && json_receiver?(receiver)
end

.cache_if_call?(receiver, method_name) ⇒ Boolean

Check if this is a conditional cache call



50
51
52
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/cache_call_detector.rb', line 50

def cache_if_call?(receiver, method_name)
  method_name == :cache_if! && json_receiver?(receiver)
end

.cache_method?(method_name) ⇒ Boolean

Check if method is any cache-related method



57
58
59
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/cache_call_detector.rb', line 57

def cache_method?(method_name)
  CACHE_METHODS.include?(method_name.to_s)
end

.categorySymbol



29
30
31
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/cache_call_detector.rb', line 29

def category
  :meta
end

.descriptionString



34
35
36
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/cache_call_detector.rb', line 34

def description
  "Cache calls (json.cache!, json.cache_if!)"
end

.extract_cache_condition(args) ⇒ Parser::AST::Node?

Extract cache condition from cache_if! arguments



74
75
76
77
78
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/cache_call_detector.rb', line 74

def extract_cache_condition(args)
  return nil if args.length < 2

  args.first # First argument is the condition
end

.extract_cache_key(args) ⇒ String?

Extract cache key from arguments



64
65
66
67
68
69
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/cache_call_detector.rb', line 64

def extract_cache_key(args)
  return nil if args.empty?

  first_arg = args.first
  extract_string_value(first_arg)
end

.extract_cache_options(args) ⇒ Hash

Extract cache options from arguments



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/cache_call_detector.rb', line 90

def extract_cache_options(args)
  options = {}

  args.each do |arg|
    next unless arg.type == :hash

    arg.children.each do |pair|
      next unless pair.type == :pair

      key_node, value_node = pair.children
      next unless key_node.type == :sym

      key = key_node.children.first
      value = extract_string_value(value_node) || value_node
      options[key] = value
    end
  end

  options
end

.handles?(receiver, method_name, _args = []) ⇒ Boolean

Check if this detector handles the method call



18
19
20
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/cache_call_detector.rb', line 18

def handles?(receiver, method_name, _args = [])
  cache_call?(receiver, method_name) || cache_if_call?(receiver, method_name)
end

.has_block?(node) ⇒ Boolean

Check if cache call has block



83
84
85
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/cache_call_detector.rb', line 83

def has_block?(node)
  node.type == :block
end

.priorityInteger

Medium priority - caching doesn't affect schema structure



24
25
26
# File 'lib/rails-openapi-gen/parsers/jbuilder/call_detectors/cache_call_detector.rb', line 24

def priority
  5
end