overpath 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: f8be652dae7a95b56a2a470dac2e794bcca7ede3
4
- data.tar.gz: 075eeb68462839818003675154bf2462f717da24
3
+ metadata.gz: 769f40dd3be6cce71d4b04c48f8df3e0f3c69ec5
4
+ data.tar.gz: 5c5a60aaa63810e09956e2fe01455eabcba0e091
5
5
  SHA512:
6
- metadata.gz: 70b53e13618d162fc0f97536b032ec5d37593ddd3419b83045de5085e48b58c09e1616ea5fcffa6b05e54340c391772de5b84717ac826e2f989c8fab32b0e972
7
- data.tar.gz: 7afd3db406c31a07d49d2c401cb83a6f97a55b2276645509ce8ddcef6880bee57a82b6dd40fa9dff42ce425e5544db767eecb6c925e6f81a3ec83220a5a4f2c0
6
+ metadata.gz: cbb731821cbe0107be6123f9b2be67af64c7f71b3f201589ad872e9e7d6dff8b6e889b0e9efdb739f02821a0d98800429064e7bdc4d172c404ff683aad59a4cf
7
+ data.tar.gz: 29442c09573d31abf575a08a80b091d351375ce047b86e220c54e6ffd195b61ea757298e65eb8ba591575ac62a1d924c893b19cc03314cb0202c2a45c031a22c
@@ -7,7 +7,7 @@ program_desc 'Valhalla awaits!'
7
7
  program_long_desc 'Find your path before Ragnarök comes!'
8
8
  default_command 'help'
9
9
  hide_commands_without_desc true
10
- version '0.0.1'
10
+ version '0.0.2'
11
11
  sort_help :manually
12
12
  accept(File) do |string|
13
13
  File.path(string)
@@ -18,15 +18,17 @@ flag %i[file], desc: 'Specify a file to store paths',
18
18
  type: File
19
19
 
20
20
  pre do |global_options, _command, _options, _args|
21
+ @needs_save = false
21
22
  path = global_options[:file]
22
23
  dir = File.dirname(path)
23
24
  Dir.mkdir(dir) unless Dir.exist?(dir)
24
25
  @table = PathTable.new(path)
26
+ @table.history_limit = 24
25
27
  @table.load
26
28
  end
27
29
 
28
30
  post do
29
- @table.save
31
+ @table.save if @needs_save
30
32
  end
31
33
 
32
34
  desc 'Set one path with one key'
@@ -81,12 +83,14 @@ command :fav do |c|
81
83
  key_value = [@table.favorite, @table.table[@table.favorite]]
82
84
  puts PathPrinter.str_del(key_value)
83
85
  @table.favorite = nil
86
+ @needs_save = true
84
87
  end
85
88
  elsif args[0]
86
89
  value = @table.table[args[0]]
87
90
  if value
88
91
  @table.favorite = args[0]
89
92
  puts PathPrinter.str_mark([@table.favorite, value], @table.favorite)
93
+ @needs_save = true
90
94
  end
91
95
  elsif @table.favorite
92
96
  key_value = [@table.favorite, @table.table[@table.favorite]]
@@ -145,6 +149,7 @@ command :mv do |c|
145
149
  @table.table[args[0]] = another_value
146
150
  puts PathPrinter.str([args[0], another_value])
147
151
  end
152
+ @needs_save = true
148
153
  end
149
154
  end
150
155
  end
@@ -157,6 +162,7 @@ command :so do |c|
157
162
  true,
158
163
  true,
159
164
  @table.favorite)
165
+ @needs_save = true
160
166
  end
161
167
  end
162
168
 
@@ -171,6 +177,7 @@ command :rm do |c|
171
177
  @table.favorite = nil if key == @table.favorite
172
178
  value = @table.table.delete(key)
173
179
  puts PathPrinter.str_del([key, value]) if value
180
+ @needs_save = true
174
181
  end
175
182
  end
176
183
  end
@@ -5,6 +5,7 @@ class PathTable
5
5
  def initialize(file_path)
6
6
  @file_path = file_path
7
7
  @table = {}
8
+ @history_limit = 5
8
9
  end
9
10
  PATHTABLE_FAVORITE_KEY = 'PATHTABLE_FAVORITE_KEY'.freeze
10
11
  def save
@@ -20,7 +21,7 @@ class PathTable
20
21
  table = @favorite ? @table.merge(favorite) : @table
21
22
  file.puts JSON.generate(table)
22
23
  File.foreach(@file_path).with_index do |line, i|
23
- break if i > 14
24
+ break if i > (@history_limit - 1)
24
25
  file.puts line
25
26
  end
26
27
  end
@@ -38,4 +39,5 @@ class PathTable
38
39
  end
39
40
  attr_accessor :table
40
41
  attr_accessor :favorite
42
+ attr_accessor :history_limit
41
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overpath
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fang Qiuming
@@ -63,7 +63,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
63
  requirements:
64
64
  - - ">="
65
65
  - !ruby/object:Gem::Version
66
- version: '0'
66
+ version: 2.0.0
67
67
  required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  requirements:
69
69
  - - ">="