Class: Veye::Settings
- Inherits:
-
Object
- Object
- Veye::Settings
- Defined in:
- lib/veye/settings.rb
Overview
This class includes methods to manage project specific settings to make it recurrent usage simpler for users
Class Method Summary collapse
- .default_options ⇒ Object
-
.dump(path, options) ⇒ Object
saves map of options into settings file ps: it overwrites whole content in settings file.
- .file_fullpath(path) ⇒ Object
- .filename ⇒ Object
-
.init(path, options) ⇒ Object
initializes default VersionEye settings file and saves it into the file.
-
.load(path) ⇒ Object
read config file from current working directory it returns nil if settings file doesnt exists or not readable otherwise it returns a map of settings.
Class Method Details
.default_options ⇒ Object
17 18 19 |
# File 'lib/veye/settings.rb', line 17 def self. @default_options end |
.dump(path, options) ⇒ Object
saves map of options into settings file ps: it overwrites whole content in settings file
38 39 40 41 |
# File 'lib/veye/settings.rb', line 38 def self.dump(path, ) file_path = file_fullpath(path) File.open(file_path, 'w') {|f| f.write(.to_json) } end |
.file_fullpath(path) ⇒ Object
21 22 23 24 25 |
# File 'lib/veye/settings.rb', line 21 def self.file_fullpath(path) path ||= Dir.pwd file_path = "#{path}/#{@filename}" File.absolute_path(file_path) end |
.filename ⇒ Object
13 14 15 |
# File 'lib/veye/settings.rb', line 13 def self.filename @filename end |
.init(path, options) ⇒ Object
initializes default VersionEye settings file and saves it into the file
44 45 46 47 48 |
# File 'lib/veye/settings.rb', line 44 def self.init(path, ) opts = @default_options.merge() dump(path, opts) opts end |
.load(path) ⇒ Object
read config file from current working directory it returns nil if settings file doesnt exists or not readable otherwise it returns a map of settings
30 31 32 33 34 |
# File 'lib/veye/settings.rb', line 30 def self.load(path) file_path = file_fullpath(path) return unless File.exist?(file_path) JSON.load(File.open(file_path, 'r')) end |