Class: JekyllWKD::KeyFile

Inherits:
Jekyll::StaticFile
  • Object
show all
Defined in:
lib/jekyll-wkd/keyfile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, base, dir, name, fpr, adv = true) ⇒ KeyFile

Returns a new instance of KeyFile.



10
11
12
13
14
# File 'lib/jekyll-wkd/keyfile.rb', line 10

def initialize site, base, dir, name, fpr, adv = true
  @fingerprint = fpr
  @advanced = adv
  super site, base, dir, name
end

Instance Attribute Details

#advancedObject (readonly)

Returns the value of attribute advanced.



8
9
10
# File 'lib/jekyll-wkd/keyfile.rb', line 8

def advanced
  @advanced
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



8
9
10
# File 'lib/jekyll-wkd/keyfile.rb', line 8

def fingerprint
  @fingerprint
end

Instance Method Details

#destination(dest) ⇒ Object



16
17
18
19
20
21
# File 'lib/jekyll-wkd/keyfile.rb', line 16

def destination dest
  @destination ||= {}
  @destination[dest] ||= @site.in_dest_dir(
    dest, PGP_PATH, advanced ? domain : "", "hu", hash
  )
end

#domainObject



36
37
38
# File 'lib/jekyll-wkd/keyfile.rb', line 36

def domain
  @domain ||= pgpkey.email.split("@").last
end

#hashObject



44
45
46
# File 'lib/jekyll-wkd/keyfile.rb', line 44

def hash
  @hash ||= ZBase32.encode Digest::SHA1.digest username
end

#usernameObject



40
41
42
# File 'lib/jekyll-wkd/keyfile.rb', line 40

def username
  @username || pgpkey.email.split("@").first
end

#write(dest) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/jekyll-wkd/keyfile.rb', line 23

def write dest
  dest_path = destination dest
  return false if File.exist?(dest_path) && !modified?

  self.class.mtimes[path] = mtime

  FileUtils.mkdir_p(File.dirname(dest_path))
  FileUtils.rm(dest_path) if File.exist?(dest_path)

  File.open(dest_path, "w") { |f| pgpkey.export output: f }
  true
end