Class: Adva::Static::Export::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/adva/static/export/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Store

Returns a new instance of Store.



9
10
11
12
# File 'lib/adva/static/export/store.rb', line 9

def initialize(dir)
  @dir = Pathname.new(dir.to_s)
  FileUtils.mkdir_p(dir)
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



7
8
9
# File 'lib/adva/static/export/store.rb', line 7

def dir
  @dir
end

Instance Method Details

#exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/adva/static/export/store.rb', line 14

def exists?(path)
  File.exists?(dir.join(path.filename))
end

#purge(path) ⇒ Object



24
25
26
# File 'lib/adva/static/export/store.rb', line 24

def purge(path)
  dir.join(path.filename).delete rescue Errno::ENOENT
end

#write(path, body) ⇒ Object



18
19
20
21
22
# File 'lib/adva/static/export/store.rb', line 18

def write(path, body)
  path = dir.join(path.filename)
  FileUtils.mkdir_p(File.dirname(path))
  File.open(path, 'w+') { |f| f.write(body) }
end