Class: S7::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/s7/configuration.rb

Overview

設定を表現する。

Constant Summary collapse

DEFAULT_CIPHER_TYPE =

デフォルトの秘密鍵暗号方式。

"AES-256-CBC"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(world) ⇒ Configuration

Returns a new instance of Configuration.



17
18
19
20
# File 'lib/s7/configuration.rb', line 17

def initialize(world)
  @world = world
  @cipher_type = DEFAULT_CIPHER_TYPE
end

Instance Attribute Details

#cipher_typeObject

秘密鍵暗号方式。



15
16
17
# File 'lib/s7/configuration.rb', line 15

def cipher_type
  @cipher_type
end

#worldObject

World オブジェクト。



12
13
14
# File 'lib/s7/configuration.rb', line 12

def world
  @world
end

Instance Method Details

#load(path) ⇒ Object

設定をファイルから読み込む。



34
35
36
37
38
39
# File 'lib/s7/configuration.rb', line 34

def load(path)
  File.open(path, "rb") do |f|
    hash = YAML.load(f.read)
    @cipher_type = hash["cipher_type"]
  end
end

#save(path) ⇒ Object

設定をファイルに書き出す。



23
24
25
26
27
28
29
30
31
# File 'lib/s7/configuration.rb', line 23

def save(path)
  hash = {
    "cipher_type" => @cipher_type,
  }
  FileUtils.touch(path)
  File.open(path, "wb") do |f|
    f.write(hash.to_yaml)
  end
end