nub 0.0.128 → 0.0.132

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/nub/config.rb +24 -18
  3. data/lib/nub/user.rb +5 -7
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc495fbfdb92d3b2cbd5f8b34373e4ffd7ccfc5f9ddfede0140d1e52c8a2e89a
4
- data.tar.gz: 27067ccd9364da31e08077f0cedce3fcf46594c6f2522a115695e5d310e908bf
3
+ metadata.gz: 6716e8061fc1229e2f09ee178f5de3a7f393fc4813293eacb47212a51e6fc066
4
+ data.tar.gz: 41b6d8ade5c092f30bfac71f476d8391dfaad58c1e738519eff525fc6fcc9362
5
5
  SHA512:
6
- metadata.gz: c16bb3b7b76f1d2c80a3bcc05044eb81105fa1014e33c15c82bfb1930b739cede6a40dd27606ee56bfcb846efdbb805bc574bdd4395f867994fcb21ccd9079ec
7
- data.tar.gz: fb633b15decdf82c281d235a8e0fe1c1db04c30175cbef81a5680522d528cd87329b821525bced89e25aecc75681b6adace6438282038c5a511a4955d7a73158
6
+ metadata.gz: d699b969b580355a1ca0c6a5000a311d6aebe25e99ec42f7fb775cfeed48f335db762e7e13d57f1800b2e5c85f69b7d3a6d265fc7f5f3b1c9c1dded884b26d53
7
+ data.tar.gz: 77f0c05ccf459386ff39a6d274a4d11ae212a1ff88483ee601d4ecf731da10bebd0c7f10f6f7672f3244795e9a3bfbb2586599d282e9102279a362ebe0deccfe
data/lib/nub/config.rb CHANGED
@@ -22,19 +22,19 @@
22
22
  require 'yaml'
23
23
  require 'colorize'
24
24
 
25
- require_relative 'user'
26
25
  require_relative 'log'
26
+ require_relative 'user'
27
+ require_relative 'module'
27
28
 
28
29
  # Simple YAML configuration for an application.
29
30
  # Uses singleton pattern for single source of truth
30
31
  module Config
31
32
  extend self
32
- @@_yml = {}
33
+ mattr_accessor(:path, :yml)
33
34
 
34
- # Public properties
35
- class << self
36
- attr_accessor :path
37
- end
35
+ # Defaults
36
+ @@yml = {}
37
+ @@path = ""
38
38
 
39
39
  # Singleton new alternate
40
40
  # @param config [String] name or path of the config file
@@ -42,46 +42,52 @@ module Config
42
42
 
43
43
  # Determine caller's file path to look for sidecar config
44
44
  caller_path = caller_locations(1, 1).first.path
45
- @path = File.expand_path(File.join(File.dirname(caller_path), config))
46
- if !File.exists?(@path)
47
- @path = "/home/#{User.name}/.config/#{config.split('/').first}"
45
+ @@path = File.expand_path(File.join(File.dirname(caller_path), config))
46
+ if !File.exists?(@@path)
47
+ @@path = "/home/#{User.name}/.config/#{config.split('/').first}"
48
48
  end
49
49
 
50
50
  # Open the config file or create in memory yml
51
51
  begin
52
- @@_yml = File.exists?(@path) ? YAML.load_file(@path) : {}
52
+ @@yml = File.exists?(@@path) ? YAML.load_file(@@path) : {}
53
53
  rescue Exception => e
54
54
  Log.die(e)
55
55
  end
56
56
 
57
- return nil
57
+ return Config
58
+ end
59
+
60
+ # Set back to defaults read for init again
61
+ def reset
62
+ self.yml = {}
63
+ self.path = ""
58
64
  end
59
65
 
60
66
  # Simple bool whether the config exists or not on disk
61
67
  def exists?
62
- return File.exists?(@path)
68
+ return File.exists?(@@path)
63
69
  end
64
70
 
65
71
  # Hash like getter
66
72
  def [](key)
67
- return @@_yml[key]
73
+ return @@yml[key]
68
74
  end
69
75
 
70
76
  # Hash like setter
71
77
  def []=(key, val)
72
- return @@_yml[key] = val
78
+ return @@yml[key] = val
73
79
  end
74
80
 
75
81
  # Get the given key and raise an error if it doesn't exist
76
82
  def get!(key)
77
- Log.die("couldn't find '#{key}' in config") if !@@_yml.key?(key)
78
- return @@_yml[key]
83
+ Log.die("couldn't find '#{key}' in config") if !@@yml.key?(key)
84
+ return @@yml[key]
79
85
  end
80
86
 
81
87
  # Save the config file
82
88
  def save
83
- return unless @@_yml
84
- File.open(@path, 'w', 0600){|f| f.write(@@_yml.to_yaml)}
89
+ return unless @@yml
90
+ File.open(@@path, 'w', 0600){|f| f.write(@@yml.to_yaml)}
85
91
  end
86
92
  end
87
93
 
data/lib/nub/user.rb CHANGED
@@ -28,16 +28,15 @@ module User
28
28
 
29
29
  # Drop root privileges to original user
30
30
  # Only affects ruby commands not system commands
31
- # Params:
32
- # +returns+:: uid, gid of prior user
31
+ # @returns [uid, gid] of root user
33
32
  def drop_privileges()
34
33
  uid = gid = nil
35
34
 
36
35
  if Process.uid.zero?
37
36
  uid, gid = Process.uid, Process.gid
38
37
  sudo_uid, sudo_gid = ENV['SUDO_UID'].to_i, ENV['SUDO_GID'].to_i
39
- Process::Sys.setegid(sudo_uid)
40
- Process::Sys.seteuid(sudo_gid)
38
+ Process::Sys.seteuid(sudo_uid)
39
+ Process::Sys.setegid(sudo_gid)
41
40
  end
42
41
 
43
42
  return uid, gid
@@ -45,9 +44,8 @@ module User
45
44
 
46
45
  # Raise privileges if dropped earlier
47
46
  # Only affects ruby commands not system commands
48
- # Params:
49
- # +uid+:: uid of user to assume
50
- # +gid+:: gid of user to assume
47
+ # @param uid [String] uid of user to assume
48
+ # @param gid [String] gid of user to assume
51
49
  def raise_privileges(uid, gid)
52
50
  if uid and gid
53
51
  Process::Sys.seteuid(uid)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.128
4
+ version: 0.0.132
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Crummett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-24 00:00:00.000000000 Z
11
+ date: 2018-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize