Class: Sudo::Configuration
- Inherits:
-
Hash
- Object
- Hash
- Sudo::Configuration
- Defined in:
- lib/sudo/configuration.rb
Overview
Configuration class for managing global sudo settings
Constant Summary collapse
- DEFAULTS =
{ timeout: 10, retries: 3, socket_dir: '/tmp', sudo_askpass: nil, load_gems: true }.freeze
Instance Method Summary collapse
-
#initialize(config = {}, **kwargs) ⇒ Configuration
constructor
A new instance of Configuration.
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
- #socket_path(pid, random_id) ⇒ Object
Constructor Details
#initialize(config = {}, **kwargs) ⇒ Configuration
Returns a new instance of Configuration.
19 20 21 22 23 |
# File 'lib/sudo/configuration.rb', line 19 def initialize(config = {}, **kwargs) super() merge!(@configuration || DEFAULTS) merge!(config.merge(kwargs).slice(*DEFAULTS.keys)) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sudo/configuration.rb', line 29 def method_missing(method, *args, &block) method_name = method.to_s if method_name.end_with?('=') key = method_name.chomp('=').to_sym if DEFAULTS.key?(key) self[key] = args.first else super end elsif DEFAULTS.key?(method) self[method] else super end end |
Instance Method Details
#respond_to_missing?(method, include_private = false) ⇒ Boolean
46 47 48 49 50 |
# File 'lib/sudo/configuration.rb', line 46 def respond_to_missing?(method, include_private = false) method_name = method.to_s key = method_name.end_with?('=') ? method_name.chomp('=').to_sym : method DEFAULTS.key?(key) || super end |
#socket_path(pid, random_id) ⇒ Object
25 26 27 |
# File 'lib/sudo/configuration.rb', line 25 def socket_path(pid, random_id) File.join(self[:socket_dir], "rubysu-#{pid}-#{random_id}") end |