kukushka 0.1.10 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9db49c16a0aea63858b52800a977d161d39736202ea11efd22a671f50ebb1ac0
4
- data.tar.gz: 207e13e36c4253212426ce27545b619c51794d7af3ec6989dab7da48e5667a0f
3
+ metadata.gz: 87f7d2da9cffcb01bf3b7dba61f237ab4f75f5e47451657832371a1222cdd754
4
+ data.tar.gz: 7363f9843f96e990b3ec29ac31e13cfe74339ca402ce2e2a9672f3d57bcd440b
5
5
  SHA512:
6
- metadata.gz: f13272fdf33abf33d5d926eb42798eb61be81786871deb14ccff81289e306004bfbf8717d3230be051eb368413667f3cb4a207fd3f2143d161fa82d981b331b7
7
- data.tar.gz: e393403061baeb44b50b89297a7dceaf6f28356fd38b5996448a118e2858726d6e8f5cd455eddcea62ff2141caeb33b227bf2b5a2e98ab4364a788e1909431ca
6
+ metadata.gz: c4e589c8f6d58c55700e9d080d01d8903f130c44b17ff3b70072fdf8a1342fa2cf2e11a7c5922f90785e6aeaded821986b3c5f9eb56b00ec142a69057d608154
7
+ data.tar.gz: bca9109ddb4d06224e25e27dc2cdd3a972c260e9242a4c520accfaa1e6228b7590955d9c10de299ffd193abe92e41fc384b2ec8f6e8234b5a4f556858e740f96
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kukushka (0.1.10)
4
+ kukushka (0.1.12)
5
5
  commander (~> 4.4)
6
6
  rainbow (~> 3.0)
7
7
  redis (~> 5.3)
data/exe/kuku CHANGED
@@ -7,7 +7,6 @@ require 'redis'
7
7
  require 'redis-namespace'
8
8
  require 'json'
9
9
 
10
-
11
10
  redis_connection = Redis.new
12
11
  redis = Redis::Namespace.new(:kukushka, redis: redis_connection)
13
12
 
@@ -21,6 +20,10 @@ Commander.configure do
21
20
  c.syntax = 'kuku sample'
22
21
  c.description = 'Show next sample'
23
22
  c.action do |args, options|
23
+ unless redis.get('source')
24
+ Kukushka.restore(redis)
25
+ end
26
+
24
27
  next unless redis.get('enabled') == 'true'
25
28
  annoying = redis.get(:annoying).to_i
26
29
  if annoying > 0
@@ -36,6 +39,7 @@ Commander.configure do
36
39
  c.syntax = 'kuku init'
37
40
  c.description = 'Default initiation'
38
41
  c.action do |args, options|
42
+ Kukushka.reset(redis)
39
43
  # res = Kukushka.kuku(ARGV)
40
44
  # puts res if res
41
45
  end
@@ -45,16 +49,17 @@ Commander.configure do
45
49
  c.syntax = 'kuku annoying [int]'
46
50
  c.description = 'Sets annoying factor'
47
51
  c.action do |args, options|
48
- redis.set(:annoying, args.first)
49
- # puts res if res
52
+ Kukushka.store({ annoying: args.first })
53
+ Kukushka.restore(redis)
50
54
  end
51
55
  end
52
56
 
53
- command :output do |c|
54
- c.syntax = 'kuku output simple'
55
- c.description = 'Sets output format'
57
+ command :format do |c|
58
+ c.syntax = 'kuku format simple'
59
+ c.description = 'format output'
56
60
  c.action do |args, options|
57
- redis.set(:output, args.first)
61
+ Kukushka.store({ format: args.first })
62
+ Kukushka.restore(redis)
58
63
  end
59
64
  end
60
65
 
@@ -62,24 +67,46 @@ Commander.configure do
62
67
  c.syntax = 'kuku source file_path'
63
68
  c.description = 'Add new source'
64
69
  c.action do |args, options|
65
- lines = File.readlines(args.first, chomp: true)
66
- redis.set(:lines, lines.to_json)
70
+ # lines = File.readlines(args.first, chomp: true)
71
+ # redis.set(:lines, lines.to_json)
72
+ Kukushka.store({source: args.first})
73
+ Kukushka.restore(redis)
67
74
  end
68
75
  end
69
76
 
70
77
  command :on do |c|
71
78
  c.syntax = 'kuku on'
72
- c.description = 'Disable'
79
+ # c.description = 'enable'
73
80
  c.action do |args, options|
74
- redis.set('enabled', true)
81
+ Kukushka.store({enabled: true})
82
+ Kukushka.restore(redis)
75
83
  end
76
84
  end
77
85
 
78
86
  command :off do |c|
79
87
  c.syntax = 'kuku off'
88
+ # c.description = 'disable'
89
+ c.action do |args, options|
90
+ Kukushka.store({enabled: false})
91
+ Kukushka.restore(redis)
92
+ end
93
+ end
94
+
95
+ command :status do |c|
96
+ c.syntax = 'kuku status'
80
97
  c.description = 'disable'
81
98
  c.action do |args, options|
82
- redis.set('enabled', false)
99
+ %i(source enabled format counter from circle annoying).each do |key|
100
+ puts "#{key}: #{redis.get(key.to_s)}"
101
+ end
102
+ end
103
+ end
104
+
105
+ command :reset do |c|
106
+ c.syntax = 'kuku reset'
107
+ c.description = 'reset config'
108
+ c.action do |args, options|
109
+ Kukushka.reset(redis)
83
110
  end
84
111
  end
85
112
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kukushka
4
- VERSION = "0.1.10"
4
+ VERSION = "0.1.12"
5
5
  end
data/lib/kukushka.rb CHANGED
@@ -7,11 +7,81 @@ require 'yaml'
7
7
  module Kukushka
8
8
  EXAMPLE_SOURCE ||= File.dirname(__FILE__) + '/../fixtures/pl_001.txt'
9
9
  DEFULAT_LINES = File.readlines(EXAMPLE_SOURCE, chomp: true)
10
+ CONFIG_ENTRIES = %i(source enabled annoying format counter from circle)
10
11
 
11
12
  def self.kuku(redis)
12
13
  Kukushka.kuku(redis)
13
14
  end
14
15
 
16
+ def self.store(config_entry)
17
+ Config.store(config_entry)
18
+ end
19
+
20
+ def self.restore(redis)
21
+ Config.restore(redis)
22
+ end
23
+
24
+ def self.reset(redis)
25
+ Config.reset(redis)
26
+ end
27
+
28
+ class Config
29
+ CONFIG_FILE = File.dirname(__FILE__) + '/../tmp/config/kuku.yaml'
30
+ SOURCE = File.dirname(__FILE__) + '/../spec/fixtures/pl_001.txt'
31
+
32
+ CONFIG_DIR = File.dirname(CONFIG_FILE)
33
+ dir = File.dirname(CONFIG_FILE)
34
+ FileUtils.mkdir_p(dir) unless File.exist?(dir)
35
+
36
+ def self.store(config_entry)
37
+ new.store(config_entry)
38
+ end
39
+
40
+ def self.restore(redis)
41
+ new.restore(redis)
42
+ end
43
+
44
+ def self.reset(redis)
45
+ config = new
46
+ config.reset
47
+ config.restore(redis)
48
+ end
49
+
50
+ def reset
51
+ config = {
52
+ source: SOURCE,
53
+ enabled: true,
54
+ counter: 0,
55
+ from: 0,
56
+ circle: 0,
57
+ annoying: 0,
58
+ format: nil,
59
+ }
60
+
61
+ File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml }
62
+ end
63
+
64
+ def store(config_entry)
65
+ raise 'unknown config' if (config_entry.keys - CONFIG_ENTRIES).any?
66
+
67
+ config = YAML::load_file(CONFIG_FILE)
68
+ config.merge!(config_entry)
69
+ File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml }
70
+ end
71
+
72
+ def restore(redis)
73
+ config.each do |key, value|
74
+ redis.set(key, value)
75
+ end
76
+ end
77
+
78
+ private
79
+
80
+ def config
81
+ @config ||= YAML::load_file(CONFIG_FILE)
82
+ end
83
+ end
84
+
15
85
  class Kukushka
16
86
  def self.kuku(redis)
17
87
  new(redis).kuku
@@ -55,7 +125,7 @@ module Kukushka
55
125
  end
56
126
 
57
127
 
58
- return lines[counter] if redis.get(:output) == 'simple'
128
+ return lines[counter] if redis.get(:format) == 'simple'
59
129
  return "#{lines[counter]} #{counter} [#{from}-#{to}/#{lines.size - 1}]"
60
130
  end
61
131
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kukushka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serge Kislak
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-02 00:00:00.000000000 Z
11
+ date: 2025-01-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rainbow