kukushka 0.1.9 → 0.1.11

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: 94f4bb61fb7d9a47ef5b89702b98ea7bf1b73e80625b848734d4cd891f5febf0
4
- data.tar.gz: 663865c3e2b233d58d4347b21795986971a255a7a11ce58768fc06f4190470a3
3
+ metadata.gz: 1868389f90b7966de784b7c01ef008fb3112a851dbc90a8f09acf57df8120bd8
4
+ data.tar.gz: 4ffa3548b1f651dc8dbb459718dd2fdc2f4f0dc1844c198cc38b49cc6cb139a3
5
5
  SHA512:
6
- metadata.gz: e24ce23687b82d96cbb4d28a142ff046c499b5bbe6e6b86e93c860a941c845c6a280c21dbfbce9abcdf4af59f6cb97452ae91eef3f2bd1ff9874d955852e530f
7
- data.tar.gz: 0d5757c62b60e0dc17ff637934c69b2d230c46df14741b10b336d48e75d37bbf13149a02d43d2f20675b366b37dbe8c2a04673a3edfa265040019911465622ad
6
+ metadata.gz: 772d155cd2e503dd1e0e365e1c1d2a9a216c28111d2661fd222b1f33f3146dee452ed0fbf8e543b9b1d6a230bb7f69bfb79b9ba1f23ec4f8325c895b1b9f8fcb
7
+ data.tar.gz: a3ac0c16a33245cc6afa1beba585ff4a0ada8982d44f2b908881e16a65e3f52344d4106395901dea9fa7465b06a882dd5e56f5680056ba9d3e769ee7ac1dce3a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kukushka (0.1.8)
4
+ kukushka (0.1.11)
5
5
  commander (~> 4.4)
6
6
  rainbow (~> 3.0)
7
7
  redis (~> 5.3)
@@ -11,7 +11,7 @@ GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
13
  ast (2.4.2)
14
- bigdecimal (3.1.8)
14
+ bigdecimal (3.1.9)
15
15
  coderay (1.1.3)
16
16
  commander (4.6.0)
17
17
  highline (~> 2.0.0)
@@ -26,7 +26,7 @@ GEM
26
26
  logger
27
27
  zeitwerk (~> 2.6)
28
28
  dry-inflector (1.1.0)
29
- dry-initializer (3.1.1)
29
+ dry-initializer (3.2.0)
30
30
  dry-logic (1.5.0)
31
31
  concurrent-ruby (~> 1.0)
32
32
  dry-core (~> 1.0, < 2)
@@ -47,15 +47,15 @@ GEM
47
47
  dry-logic (~> 1.4)
48
48
  zeitwerk (~> 2.6)
49
49
  highline (2.0.3)
50
- json (2.9.0)
50
+ json (2.9.1)
51
51
  language_server-protocol (3.17.0.3)
52
- logger (1.6.3)
52
+ logger (1.6.4)
53
53
  method_source (1.1.0)
54
54
  parallel (1.26.3)
55
55
  parser (3.3.6.0)
56
56
  ast (~> 2.4.1)
57
57
  racc
58
- pry (0.15.0)
58
+ pry (0.15.2)
59
59
  coderay (~> 1.1)
60
60
  method_source (~> 1.0)
61
61
  racc (1.8.1)
@@ -72,8 +72,8 @@ GEM
72
72
  parser (~> 3.3.0)
73
73
  rainbow (>= 2.0, < 4.0)
74
74
  rexml (~> 3.1)
75
- regexp_parser (2.9.3)
76
- rexml (3.3.9)
75
+ regexp_parser (2.10.0)
76
+ rexml (3.4.0)
77
77
  rspec (3.13.0)
78
78
  rspec-core (~> 3.13.0)
79
79
  rspec-expectations (~> 3.13.0)
@@ -100,10 +100,10 @@ GEM
100
100
  rubocop-ast (1.37.0)
101
101
  parser (>= 3.3.1.0)
102
102
  ruby-progressbar (1.13.0)
103
- unicode-display_width (3.1.2)
103
+ unicode-display_width (3.1.3)
104
104
  unicode-emoji (~> 4.0, >= 4.0.4)
105
105
  unicode-emoji (4.0.4)
106
- zeitwerk (2.6.18)
106
+ zeitwerk (2.7.1)
107
107
 
108
108
  PLATFORMS
109
109
  arm64-darwin-22
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,7 +20,15 @@ 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'
28
+ annoying = redis.get(:annoying).to_i
29
+ if annoying > 0
30
+ next if 1.0/annoying < rand
31
+ end
25
32
 
26
33
  res = Kukushka.kuku(redis)
27
34
  puts res if res
@@ -37,18 +44,39 @@ Commander.configure do
37
44
  end
38
45
  end
39
46
 
47
+ command :annoying do |c|
48
+ c.syntax = 'kuku annoying [int]'
49
+ c.description = 'Sets annoying factor'
50
+ c.action do |args, options|
51
+ redis.set(:annoying, args.first)
52
+ Kukushka.store(redis)
53
+ # puts res if res
54
+ end
55
+ end
56
+
57
+ command :format do |c|
58
+ c.syntax = 'kuku format simple'
59
+ c.description = 'Output format'
60
+ c.action do |args, options|
61
+ redis.set(:format, args.first)
62
+ Kukushka.store(redis)
63
+ end
64
+ end
65
+
40
66
  command :source do |c|
41
67
  c.syntax = 'kuku source file_path'
42
68
  c.description = 'Add new source'
43
69
  c.action do |args, options|
44
70
  lines = File.readlines(args.first, chomp: true)
71
+ redis.set(:source, args.first)
45
72
  redis.set(:lines, lines.to_json)
73
+ Kukushka.store(redis)
46
74
  end
47
75
  end
48
76
 
49
77
  command :on do |c|
50
78
  c.syntax = 'kuku on'
51
- c.description = 'Disable'
79
+ # c.description = 'enable'
52
80
  c.action do |args, options|
53
81
  redis.set('enabled', true)
54
82
  end
@@ -56,9 +84,27 @@ Commander.configure do
56
84
 
57
85
  command :off do |c|
58
86
  c.syntax = 'kuku off'
59
- c.description = 'disable'
87
+ # c.description = 'disable'
60
88
  c.action do |args, options|
61
89
  redis.set('enabled', false)
62
90
  end
63
91
  end
92
+
93
+ command :status do |c|
94
+ c.syntax = 'kuku status'
95
+ c.description = 'disable'
96
+ c.action do |args, options|
97
+ %i(source enabled annoying output counter from circle).each do |key|
98
+ puts "#{key}: #{redis.get(key.to_s)}"
99
+ end
100
+ end
101
+ end
102
+
103
+ command :reset do |c|
104
+ c.syntax = 'kuku reset'
105
+ c.description = 'reset config'
106
+ c.action do |args, options|
107
+ Kukushka.reset(redis)
108
+ end
109
+ end
64
110
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kukushka
4
- VERSION = "0.1.9"
4
+ VERSION = "0.1.11"
5
5
  end
data/lib/kukushka.rb CHANGED
@@ -12,6 +12,76 @@ module Kukushka
12
12
  Kukushka.kuku(redis)
13
13
  end
14
14
 
15
+ def self.store(redis)
16
+ Config.store(redis)
17
+ end
18
+
19
+ def self.restore(redis)
20
+ Config.restore(redis)
21
+ end
22
+
23
+ def self.reset(redis)
24
+ Config.reset(redis)
25
+ end
26
+
27
+ class Config
28
+ CONFIG_FILE = File.dirname(__FILE__) + '/../tmp/config/kuku.yaml'
29
+ SOURCE = File.dirname(__FILE__) + '/../spec/fixtures/pl_001.txt'
30
+
31
+ CONFIG_DIR = File.dirname(CONFIG_FILE)
32
+ dir = File.dirname(CONFIG_FILE)
33
+ FileUtils.mkdir_p(dir) unless File.exist?(dir)
34
+
35
+ def self.store(redis)
36
+ new.store(redis)
37
+ end
38
+
39
+ def self.restore(redis)
40
+ new.restore(redis)
41
+ end
42
+
43
+ def self.reset(redis)
44
+ config = new
45
+ config.reset
46
+ config.restore(redis)
47
+ end
48
+
49
+ def reset
50
+ config = {
51
+ source: SOURCE,
52
+ enabled: true,
53
+ counter: 0,
54
+ from: 0,
55
+ circle: 0,
56
+ annoying: 0,
57
+ output: nil,
58
+ }
59
+
60
+ File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml }
61
+ end
62
+
63
+ def store(redis)
64
+ config = {}
65
+ %i(source enabled annoying output counter from circle).each do |key|
66
+ config[key] = redis.get(key)
67
+ end
68
+
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
@@ -54,6 +124,8 @@ module Kukushka
54
124
  set_counter(from)
55
125
  end
56
126
 
127
+
128
+ return lines[counter] if redis.get(:output) == 'simple'
57
129
  return "#{lines[counter]} #{counter} [#{from}-#{to}/#{lines.size - 1}]"
58
130
  end
59
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.9
4
+ version: 0.1.11
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