Module: RMAL::Settings
- Defined in:
- lib/rMAL.rb
Overview
Configuration of password, username and apikey, for use by other modules
Class Method Summary collapse
-
.init(dir = "/") ⇒ Object
Create the settings.yml file.
-
.load(path) ⇒ Object
I know this isn’t necessary, will remove later.
-
.set(username, password, apikey) ⇒ Object
Allows the user to change the settings where necessary (and rMAL where necessary).
Class Method Details
.init(dir = "/") ⇒ Object
Create the settings.yml file
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/rMAL.rb', line 9 def self.init(dir = "/") # Default dir may not have the correct access rights granted # Allows user to not bother with the trailing / if so desired if !(dir.end_with? "/") dir = dir + "/" end # Create a settings.yml file File.open("#{dir}settings.yml", "w") do |file| end # Create global path variable for ease of use $path = "#{dir}/settings.yml" end |
.load(path) ⇒ Object
I know this isn’t necessary, will remove later
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rMAL.rb', line 33 def self.load(path) # Load the file settings = YAML::load_file path # I am aware of the serious security implications of this eval(). This needs a better fix ASAP. working = eval(settings.inspect) # Load the settings into working variables $w_username = working["username"] $w_password = working["password"] $w_apikey = working["apikey"] end |
.set(username, password, apikey) ⇒ Object
Allows the user to change the settings where necessary (and rMAL where necessary)
21 22 23 24 25 26 27 28 29 |
# File 'lib/rMAL.rb', line 21 def self.set(username, password, apikey) configuration = { 'username' => username, 'password' => password, 'apikey' => apikey } open($path, 'w') { |f| YAML.dump(configuration, f) } open($path) { |f| return f.read } end |