Class: RubyGPG2::ParameterFileContents

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_gpg2/parameter_file_contents.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ ParameterFileContents

Returns a new instance of ParameterFileContents.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 19

def initialize(opts)
  @key_type = resolve_key_type(opts)
  @key_length = resolve_key_length(opts, @key_type)
  @subkey_type = resolve_subkey_type(opts)
  @subkey_length = resolve_subkey_length(opts, @subkey_type)
  @owner_name = resolve_owner_name(opts)
  @owner_email = resolve_owner_email(opts)
  @owner_comment = resolve_owner_comment(opts)
  @expiry = resolve_expiry(opts)
  @passphrase = resolve_passphrase(opts)

  assert_required_parameters_present
end

Instance Attribute Details

#expiryObject (readonly)

Returns the value of attribute expiry.



7
8
9
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 7

def expiry
  @expiry
end

#key_lengthObject (readonly)

Returns the value of attribute key_length.



7
8
9
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 7

def key_length
  @key_length
end

#key_typeObject (readonly)

Returns the value of attribute key_type.



7
8
9
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 7

def key_type
  @key_type
end

#owner_commentObject (readonly)

Returns the value of attribute owner_comment.



7
8
9
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 7

def owner_comment
  @owner_comment
end

#owner_emailObject (readonly)

Returns the value of attribute owner_email.



7
8
9
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 7

def owner_email
  @owner_email
end

#owner_nameObject (readonly)

Returns the value of attribute owner_name.



7
8
9
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 7

def owner_name
  @owner_name
end

#passphraseObject (readonly)

Returns the value of attribute passphrase.



7
8
9
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 7

def passphrase
  @passphrase
end

#subkey_lengthObject (readonly)

Returns the value of attribute subkey_length.



7
8
9
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 7

def subkey_length
  @subkey_length
end

#subkey_typeObject (readonly)

Returns the value of attribute subkey_type.



7
8
9
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 7

def subkey_type
  @subkey_type
end

Instance Method Details

#expiry_dateObject



33
34
35
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 33

def expiry_date
  expiry == :never ? 0 : expiry
end

#in_temp_file(tmpdir = nil) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 41

def in_temp_file(tmpdir = nil)
  Tempfile.create('parameter-file', tmpdir) do |f|
    f.write(to_s)
    f.flush
    yield f
  end
end

#to_sObject



49
50
51
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 49

def to_s
  "#{to_parms.compact.join("\n")}\n"
end

#write_to(path) ⇒ Object



37
38
39
# File 'lib/ruby_gpg2/parameter_file_contents.rb', line 37

def write_to(path)
  File.open(path, 'w') { |f| f.write(to_s) }
end