kukushka 0.1.2 → 0.1.3
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/exe/kuku +10 -1
- data/lib/kukushka/version.rb +1 -1
- data/lib/kukushka.rb +69 -33
- 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: 19ee15ee498f6251378c39480c444922c0675d192582e17b9695949bd0b0f9ba
|
4
|
+
data.tar.gz: a163b7deab7dce96ed2ae54214e64b80f66bca400c8c92dc04bc8f3d5258bf92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a56fac80db7137a85fceca5520a35242a36cbee6612893ce0f7066343432003aca1736df797aaa8bb7936122465b782b6520b13f639b8712322ea3fe87db079a
|
7
|
+
data.tar.gz: 6c29a9ddf610115b4553678c7a5f8cf1806df55f82aa86ee4edbf3ed81c7864693b65194ccbb1dcb3d1f692a64afe2c826dec58a8cc4605ac97913a7471a3ab0
|
data/Gemfile.lock
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
|
15
|
+
def self.on?
|
16
|
+
Config.new.on?
|
17
|
+
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
19
|
+
def self.on!
|
20
|
+
Config.new.enable
|
21
|
+
end
|
26
22
|
|
27
|
-
attr_reader :command, :param1
|
28
23
|
|
29
|
-
|
30
|
-
|
24
|
+
class Config
|
25
|
+
CONFIG_FILE = File.dirname(__FILE__) + '/../tmp/config/kuku.yaml'
|
26
|
+
CONFIG_DIR = File.dirname(CONFIG_FILE)
|
31
27
|
|
32
|
-
|
28
|
+
def on?
|
29
|
+
exists? && config[:enabled]
|
30
|
+
end
|
33
31
|
|
34
|
-
|
35
|
-
|
36
|
-
return sample if command == 'sample'
|
37
|
-
return punchline if command.nil?
|
32
|
+
def exists?
|
33
|
+
File.exists?(CONFIG_DIR)
|
38
34
|
end
|
39
35
|
|
40
|
-
private
|
41
36
|
def init
|
42
37
|
source_file = param1
|
43
|
-
|
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]
|
64
68
|
end
|
65
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 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?
|
101
|
+
end
|
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
|