Module: PictureTag::Cache::Base

Included in:
Generated, Source
Defined in:
lib/jekyll_picture_tag/cache/base.rb

Overview

Basic image information cache functionality

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



11
12
13
# File 'lib/jekyll_picture_tag/cache/base.rb', line 11

def [](key)
  data[key]
end

#[]=(key, value) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
# File 'lib/jekyll_picture_tag/cache/base.rb', line 15

def []=(key, value)
  raise ArgumentError unless template.keys.include? key

  data[key] = value
end

#initialize(base_name) ⇒ Object



7
8
9
# File 'lib/jekyll_picture_tag/cache/base.rb', line 7

def initialize(base_name)
  @base_name = base_name
end

#writeObject

Call after updating data.



22
23
24
25
26
27
28
# File 'lib/jekyll_picture_tag/cache/base.rb', line 22

def write
  FileUtils.mkdir_p(File.join(base_directory, sub_directory))

  File.open(filename, 'w+') do |f|
    f.write JSON.generate(data)
  end
end