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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 30a1613964deb7120d6663f0cc0dbfca664640b68de9511012e5f0bdcc13e9ff
4
- data.tar.gz: d37e3e7eefda5dcbf082bf011d0ea68775127e74516d9525516fcac23455ea30
3
+ metadata.gz: 3888a46d589e195c57176e78f19727b7678022c470c739b724656e388efd70f3
4
+ data.tar.gz: eb66d404b392cfdf36bf15be889e0c7b188f78bd062350fe645a5b52878d73a5
5
5
  SHA512:
6
- metadata.gz: a8454edb8c7e97df51c7ce9c88d6ded8bf5d2f6c8bdb6421e012b04dc3e2a6014d13712ea128c5c52cbadeb3b08b2452f2f085b52cfd45e1a39a4254d0cd2d03
7
- data.tar.gz: fdd2c8014bcee1ee4889ee762a8e9775d9d1bd1b5471bdc006a3bb49362b9e2343c61416a48674c9ee58f6a989366ac5af9dd35e883f08d8204a6a33a2f49c8e
6
+ metadata.gz: ec36e38cf546aeece6ada74fa685c2ac68cd4b1d08565eee7daff4f55a4d5183348d40212b473c28b22da774c19698593bf4a24392dad62d706ff2b56d23d686
7
+ data.tar.gz: 796fcf9a585a6ad998b68ee01274db29f077f85784cc002fceed1d1e63a4d96960140cd54798b81365c4f015db4b0ac83068aa6f630eeb09e8c95c3fabc690fe
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/README.md CHANGED
@@ -36,3 +36,13 @@ function precmd() {
36
36
  }
37
37
  ```
38
38
 
39
+
40
+
41
+ ```
42
+ mkdir tmp/sk
43
+ cd tmp/sk
44
+ bundle init
45
+
46
+ gem 'pry'
47
+ gem 'kukushka', path: '/Users/Siarhei/laboratory/kukushka'
48
+ ```
data/exe/kuku CHANGED
@@ -1,5 +1,13 @@
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
+ end
9
+
10
+ return unless Kukushka.on?
11
+
12
+ res = Kukushka.kuku(ARGV)
13
+ 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.4"
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
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
- def kuku
30
- init if command == 'init'
19
+ def self.on!
20
+ Config.new.enable
21
+ end
31
22
 
32
- return INIT_CTA unless config_exists?
23
+ class Config
24
+ CONFIG_FILE = File.dirname(__FILE__) + '/../tmp/config/kuku.yaml'
25
+ CONFIG_DIR = File.dirname(CONFIG_FILE)
33
26
 
34
- return config if command == 'config'
35
- return cleanup if command == 'cleanup'
36
- return sample if command == 'sample'
37
- return punchline if command.nil?
27
+ def on?
28
+ return true unless exists?
29
+ exists? && config[:enabled]
38
30
  end
39
31
 
40
- private
41
- def init
42
- source_file = param1
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 = { 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]
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
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serge Kislak