Module: JekyllNotion::Cacheable

Defined in:
lib/jekyll-notion/cacheable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cache_path(path = nil) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/jekyll-notion/cacheable.rb', line 21

def self.cache_path(path = nil)
  if path.nil?
    File.join(Dir.getwd, ".cache", "jekyll-notion", "vcr_cassettes")
  else
    File.join(Dir.getwd, path)
  end
end

.setup(cache_dir) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jekyll-notion/cacheable.rb', line 7

def self.setup(cache_dir)
  # Using VCR to record and playback Notion API responses for caching
  VCR.configure do |config|
    config.cassette_library_dir = cache_path(cache_dir)
    config.hook_into :faraday # Faraday is used by notion-ruby-client gem
    config.filter_sensitive_data("<NOTION_TOKEN>") { ENV["NOTION_TOKEN"] }
    config.allow_http_connections_when_no_cassette = true
    config.default_cassette_options = {
      :allow_playback_repeats => true,
      :record                 => :new_episodes,
    }
  end
end

Instance Method Details

#generate(*args) ⇒ Object



29
30
31
# File 'lib/jekyll-notion/cacheable.rb', line 29

def generate(*args)
  VCR.use_cassette(resource_id) { super(*args) }
end