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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30a1613964deb7120d6663f0cc0dbfca664640b68de9511012e5f0bdcc13e9ff
4
- data.tar.gz: d37e3e7eefda5dcbf082bf011d0ea68775127e74516d9525516fcac23455ea30
3
+ metadata.gz: 19ee15ee498f6251378c39480c444922c0675d192582e17b9695949bd0b0f9ba
4
+ data.tar.gz: a163b7deab7dce96ed2ae54214e64b80f66bca400c8c92dc04bc8f3d5258bf92
5
5
  SHA512:
6
- metadata.gz: a8454edb8c7e97df51c7ce9c88d6ded8bf5d2f6c8bdb6421e012b04dc3e2a6014d13712ea128c5c52cbadeb3b08b2452f2f085b52cfd45e1a39a4254d0cd2d03
7
- data.tar.gz: fdd2c8014bcee1ee4889ee762a8e9775d9d1bd1b5471bdc006a3bb49362b9e2343c61416a48674c9ee58f6a989366ac5af9dd35e883f08d8204a6a33a2f49c8e
6
+ metadata.gz: a56fac80db7137a85fceca5520a35242a36cbee6612893ce0f7066343432003aca1736df797aaa8bb7936122465b782b6520b13f639b8712322ea3fe87db079a
7
+ data.tar.gz: 6c29a9ddf610115b4553678c7a5f8cf1806df55f82aa86ee4edbf3ed81c7864693b65194ccbb1dcb3d1f692a64afe2c826dec58a8cc4605ac97913a7471a3ab0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kukushka (0.1.1)
4
+ kukushka (0.1.2)
5
5
  rainbow (~> 3.0)
6
6
 
7
7
  GEM
data/exe/kuku CHANGED
@@ -1,5 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'yaml'
3
3
  require 'kukushka'
4
+ require 'pry'
4
5
 
5
- puts Kukushka.kuku(ARGV)
6
+ if ARGV.join('') == 'on'
7
+ Kukushka.on!
8
+ exit
9
+ end
10
+
11
+ return unless Kukushka.on?
12
+
13
+ res = Kukushka.kuku(ARGV)
14
+ puts res if res
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kukushka
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
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
- class Kukushka
18
- def self.kuku(args)
19
- new(args).kuku
20
- end
15
+ def self.on?
16
+ Config.new.on?
17
+ end
21
18
 
22
- def initialize(args)
23
- @command = args[0]
24
- @param1 = args[1]
25
- end
19
+ def self.on!
20
+ Config.new.enable
21
+ end
26
22
 
27
- attr_reader :command, :param1
28
23
 
29
- def kuku
30
- init if command == 'init'
24
+ class Config
25
+ CONFIG_FILE = File.dirname(__FILE__) + '/../tmp/config/kuku.yaml'
26
+ CONFIG_DIR = File.dirname(CONFIG_FILE)
31
27
 
32
- return INIT_CTA unless config_exists?
28
+ def on?
29
+ exists? && config[:enabled]
30
+ end
33
31
 
34
- return config if command == 'config'
35
- return cleanup if command == 'cleanup'
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 = { source: source_file }
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 config
55
- @config ||= YAML::load_file(CONFIG_FILE)
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 config_exists?
63
- File.exists?(CONFIG_DIR)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kukushka
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serge Kislak