Class: Kukushka::Config
- Inherits:
-
Object
- Object
- Kukushka::Config
- Defined in:
- lib/kukushka.rb
Constant Summary collapse
- CONFIG_FILE =
File.dirname(__FILE__) + '/../tmp/config/kuku.yaml'
- SOURCE =
File.dirname(__FILE__) + '/../spec/fixtures/pl_001.txt'
- CONFIG_DIR =
File.dirname(CONFIG_FILE)
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.reset(redis) ⇒ Object
44 45 46 47 48 |
# File 'lib/kukushka.rb', line 44 def self.reset(redis) config = new config.reset config.restore(redis) end |
.restore(redis) ⇒ Object
40 41 42 |
# File 'lib/kukushka.rb', line 40 def self.restore(redis) new.restore(redis) end |
.store(config_entry) ⇒ Object
36 37 38 |
# File 'lib/kukushka.rb', line 36 def self.store(config_entry) new.store(config_entry) end |
Instance Method Details
#reset ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/kukushka.rb', line 50 def reset config = { source: SOURCE, enabled: true, counter: 0, from: 0, circle: 0, annoying: 0, format: nil, } File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml } end |
#restore(redis) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/kukushka.rb', line 72 def restore(redis) config.each do |key, value| redis.set(key, value) end if @source = redis.get(:source) value = File.readlines(@source, chomp: true) redis.set(:lines, value) end end |
#store(config_entry) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/kukushka.rb', line 64 def store(config_entry) raise 'unknown config' if (config_entry.keys - CONFIG_ENTRIES).any? config = YAML::load_file(CONFIG_FILE) config.merge!(config_entry) File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml } end |