Class: Polites::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/polites/settings.rb

Overview

Settings is a wrapped around the combined configurations Polites writes to various Plist files in external directory.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings = {}) ⇒ Settings

Returns a new instance of Settings.

Parameters:

  • settings (Hash) (defaults to: {})


22
23
24
25
# File 'lib/polites/settings.rb', line 22

def initialize(settings = {})
  @settings = settings.to_h
  freeze
end

Class Method Details

.from_directory(path) ⇒ Polites::Settings

Read all combined .plist files in a directory into a single data structure.

Parameters:

  • path (#to_s, #to_path)

    root directory to look up .plist files in.

Returns:



14
15
16
17
18
19
# File 'lib/polites/settings.rb', line 14

def self.from_directory(path)
  Pathname(path)
    .glob('.*.plist')
    .inject({}) { |s, f| s.merge Plist.new(f).to_h }
    .then { |s| new(s) }
end

Instance Method Details

#[](key) ⇒ Object

Look up a setting by key.

Parameters:

  • key (String)

Returns:

  • (Object)


31
32
33
# File 'lib/polites/settings.rb', line 31

def [](key)
  @settings[key]
end