Class: SecretKey
- Inherits:
-
Object
- Object
- SecretKey
- Defined in:
- lib/secret_key.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(base_dir) ⇒ SecretKey
constructor
A new instance of SecretKey.
- #read ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(base_dir) ⇒ SecretKey
Returns a new instance of SecretKey.
7 8 9 10 11 12 |
# File 'lib/secret_key.rb', line 7 def initialize(base_dir) tmp = "#{base_dir}/tmp" tmp = File.(tmp) FileUtils.mkdir_p(tmp) @path = "#{tmp}/secret_key" end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
5 6 7 |
# File 'lib/secret_key.rb', line 5 def key @key end |
Instance Method Details
#read ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/secret_key.rb', line 14 def read if @key @key elsif exists? @key = File.read(@path).strip else write end end |
#write ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/secret_key.rb', line 24 def write File.open(@path, 'w') do |f| @key = RUBY_PLATFORM + rand(10000000000000).to_s @key = Digest::SHA1.hexdigest(@key) f.write(@key) end @key end |