kukushka 0.1.2 → 0.1.4
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +10 -0
- data/exe/kuku +9 -1
- data/lib/kukushka/version.rb +1 -1
- data/lib/kukushka.rb +72 -36
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3888a46d589e195c57176e78f19727b7678022c470c739b724656e388efd70f3
|
4
|
+
data.tar.gz: eb66d404b392cfdf36bf15be889e0c7b188f78bd062350fe645a5b52878d73a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec36e38cf546aeece6ada74fa685c2ac68cd4b1d08565eee7daff4f55a4d5183348d40212b473c28b22da774c19698593bf4a24392dad62d706ff2b56d23d686
|
7
|
+
data.tar.gz: 796fcf9a585a6ad998b68ee01274db29f077f85784cc002fceed1d1e63a4d96960140cd54798b81365c4f015db4b0ac83068aa6f630eeb09e8c95c3fabc690fe
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/exe/kuku
CHANGED
data/lib/kukushka/version.rb
CHANGED
data/lib/kukushka.rb
CHANGED
@@ -5,8 +5,6 @@ require 'rainbow'
|
|
5
5
|
require 'yaml'
|
6
6
|
|
7
7
|
module Kukushka
|
8
|
-
CONFIG_FILE = File.dirname(__FILE__) + '/../tmp/config/kuku.yaml'
|
9
|
-
CONFIG_DIR = File.dirname(CONFIG_FILE)
|
10
8
|
INIT_CTA = "TODO: kuku init source_file"
|
11
9
|
PROVIDE_SOURCE_CTA = "TODO: provide valid source_file path"
|
12
10
|
|
@@ -14,55 +12,96 @@ module Kukushka
|
|
14
12
|
Kukushka.kuku(args)
|
15
13
|
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize(args)
|
23
|
-
@command = args[0]
|
24
|
-
@param1 = args[1]
|
25
|
-
end
|
26
|
-
|
27
|
-
attr_reader :command, :param1
|
15
|
+
def self.on?
|
16
|
+
Config.new.on?
|
17
|
+
end
|
28
18
|
|
29
|
-
|
30
|
-
|
19
|
+
def self.on!
|
20
|
+
Config.new.enable
|
21
|
+
end
|
31
22
|
|
32
|
-
|
23
|
+
class Config
|
24
|
+
CONFIG_FILE = File.dirname(__FILE__) + '/../tmp/config/kuku.yaml'
|
25
|
+
CONFIG_DIR = File.dirname(CONFIG_FILE)
|
33
26
|
|
34
|
-
|
35
|
-
return
|
36
|
-
|
37
|
-
return punchline if command.nil?
|
27
|
+
def on?
|
28
|
+
return true unless exists?
|
29
|
+
exists? && config[:enabled]
|
38
30
|
end
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
|
32
|
+
def exists?
|
33
|
+
File.exists?(CONFIG_DIR)
|
34
|
+
end
|
43
35
|
|
36
|
+
def init(source_file)
|
37
|
+
source_file ||= File.dirname(__FILE__) + '/../spec/fixtures/pl_001.txt'
|
44
38
|
return INIT_CTA if source_file.nil?
|
45
|
-
|
46
39
|
return PROVIDE_SOURCE_CTA unless File.exist?(source_file)
|
47
40
|
|
48
41
|
dir = File.dirname(CONFIG_FILE)
|
49
42
|
FileUtils.mkdir_p(dir) unless File.exists?(dir)
|
50
|
-
config = {
|
43
|
+
config = {
|
44
|
+
source: source_file,
|
45
|
+
enabled: true
|
46
|
+
}
|
51
47
|
File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml }
|
52
48
|
end
|
53
49
|
|
54
|
-
def
|
55
|
-
|
50
|
+
def enable
|
51
|
+
config.merge!(enabled: true)
|
52
|
+
File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml }
|
53
|
+
'enabled'
|
54
|
+
end
|
55
|
+
|
56
|
+
def disable
|
57
|
+
config.merge!(enabled: false)
|
58
|
+
File.open(CONFIG_FILE, 'w') {|f| f.write config.to_yaml }
|
59
|
+
'disabled'
|
56
60
|
end
|
57
61
|
|
58
62
|
def cleanup
|
59
63
|
FileUtils.rm_rf(CONFIG_DIR) if config_exists?
|
60
64
|
end
|
61
65
|
|
62
|
-
def
|
63
|
-
|
66
|
+
def source
|
67
|
+
@source ||= YAML::load_file(CONFIG_FILE)[:source]
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
def config
|
72
|
+
@config ||= YAML::load_file(CONFIG_FILE)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
class Kukushka
|
77
|
+
def self.kuku(args)
|
78
|
+
new(args).kuku
|
79
|
+
end
|
80
|
+
|
81
|
+
def initialize(args)
|
82
|
+
@command = args[0]
|
83
|
+
@param1 = args[1]
|
84
|
+
@config = Config.new
|
85
|
+
end
|
86
|
+
|
87
|
+
attr_reader :command, :param1, :config
|
88
|
+
|
89
|
+
def kuku
|
90
|
+
config.init(param1) if command == 'init'
|
91
|
+
|
92
|
+
return INIT_CTA unless config.exists?
|
93
|
+
|
94
|
+
return config.enable if command == 'on'
|
95
|
+
return config.disable if command == 'off'
|
96
|
+
|
97
|
+
return config.cleanup if command == 'cleanup'
|
98
|
+
# return show if command == 'show'
|
99
|
+
return sample if command == 'sample'
|
100
|
+
return punchline if command.nil?
|
64
101
|
end
|
65
102
|
|
103
|
+
private
|
104
|
+
|
66
105
|
# if ARGV[0] == 'config'
|
67
106
|
# # source
|
68
107
|
# # range_number
|
@@ -75,19 +114,16 @@ module Kukushka
|
|
75
114
|
# if ARGV[0] == 'statistics'
|
76
115
|
# end
|
77
116
|
|
117
|
+
def sample
|
118
|
+
@sample ||= File.readlines(config.source, chomp: true).sample
|
119
|
+
end
|
120
|
+
|
78
121
|
def punchline
|
79
122
|
@punchline ||= Rainbow(sample).color(color).bright
|
80
123
|
end
|
81
124
|
|
82
|
-
def source
|
83
|
-
@source ||= YAML::load_file(CONFIG_FILE)[:source]
|
84
|
-
end
|
85
125
|
def color
|
86
126
|
@color ||= Rainbow::X11ColorNames::NAMES.keys.sample
|
87
127
|
end
|
88
|
-
|
89
|
-
def sample
|
90
|
-
@sample ||= File.readlines(source, chomp: true).sample
|
91
|
-
end
|
92
128
|
end
|
93
129
|
end
|