Class: AngularConfig::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/angular_config/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}, type = 'SHA256') ⇒ Config

Returns a new instance of Config.



6
7
8
9
# File 'lib/angular_config/config.rb', line 6

def initialize(config = {}, type = 'SHA256')
  @content = config
  @checksum_type = type.upcase
end

Instance Attribute Details

#checksum_typeObject (readonly)

Returns the value of attribute checksum_type.



4
5
6
# File 'lib/angular_config/config.rb', line 4

def checksum_type
  @checksum_type
end

#contentObject (readonly)

Returns the value of attribute content.



3
4
5
# File 'lib/angular_config/config.rb', line 3

def content
  @content
end

Class Method Details

.load(path, type = 'SHA256') ⇒ Object



27
28
29
# File 'lib/angular_config/config.rb', line 27

def self.load(path, type = 'SHA256')
  AngularConfig::Config.new(JSON.load(AngularConfig::File.new(path).content), type)
end

.save(data, path) ⇒ Object



31
32
33
# File 'lib/angular_config/config.rb', line 31

def self.save(data, path)
  AngularConfig::File.new(path).content = data.to_json
end

Instance Method Details

#hash_keysObject



11
12
13
14
15
16
17
# File 'lib/angular_config/config.rb', line 11

def hash_keys
  hashed_keys = content.each_with_object({}) do |(key, value), result|
    digest = load_constant("Digest::#{checksum_type}").new
    result[digest.hexdigest(key)] = value
  end
  AngularConfig::Config.new(hashed_keys)
end

#hash_valuesObject



19
20
21
22
23
24
25
# File 'lib/angular_config/config.rb', line 19

def hash_values
  hashed_values = content.each_with_object({}) do |(key, value), result|
    digest = load_constant("Digest::#{checksum_type}").new
    result[key] = digest.hexdigest(key)
  end
  AngularConfig::Config.new(hashed_values)
end