Class: Runcom::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/runcom/config.rb

Overview

A developer friendly wrapper of XDG config.

Constant Summary collapse

DEFAULT_CONTEXT =
Context.new xdg: XDG::Config

Instance Method Summary collapse

Constructor Details

#initialize(path, defaults: {}, context: DEFAULT_CONTEXT) ⇒ Config

Returns a new instance of Config.



16
17
18
19
20
21
# File 'lib/runcom/config.rb', line 16

def initialize path, defaults: {}, context: DEFAULT_CONTEXT
  @common = Paths::Common.new path, context: context
  @context = context
  @settings = defaults.deep_merge process_settings
  freeze
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

:reek:FeatureEnvy



28
29
30
# File 'lib/runcom/config.rb', line 28

def == other
  other.is_a?(Config) && hash == other.hash
end

#hashObject



34
35
36
# File 'lib/runcom/config.rb', line 34

def hash
  [common.relative, to_h, self.class].hash
end

#merge(other) ⇒ Object



23
24
25
# File 'lib/runcom/config.rb', line 23

def merge other
  self.class.new common.relative, defaults: settings.deep_merge(other.to_h), context: context
end

#to_hObject



38
39
40
# File 'lib/runcom/config.rb', line 38

def to_h
  settings
end