Class: Clerq::Settings

Inherits:
Object
  • Object
show all
Extended by:
Properties
Defined in:
lib/clerq/settings.rb

Constant Summary collapse

STORAGE =
'clerq.yml'.freeze

Instance Method Summary collapse

Methods included from Properties

property

Constructor Details

#initializeSettings

Returns a new instance of Settings.



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

def initialize
  load
end

Instance Method Details

#foldersObject



27
28
29
# File 'lib/clerq/settings.rb', line 27

def folders
  [bin, src, knb, lib, tt, assets]
end

#loadObject

TODO: load settings than can be changed by user



36
37
38
39
40
41
# File 'lib/clerq/settings.rb', line 36

def load
  return unless File.exist?(STORAGE)

  props = YAML.load(File.read(STORAGE))
  props.each{|k, v| instance_variable_set("@#{k}", v) }
end

#saveObject

TODO: it saves only changed properties

properties with default values won't be saved


45
46
47
48
49
50
51
52
53
# File 'lib/clerq/settings.rb', line 45

def save
  props = {}
  instance_variables.each{|v|
    # props[v.to_s[1..-1]] = instance_variable_get("#{v}")
    p = v.to_s[1..-1]
    props[p] = self.send(p)
  }
  File.write(STORAGE, YAML.dump(props))
end