geturl 0.5.0 → 0.6.0

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: f19981b934099e642dcd5e4ccbdb0ae206aa07b296ce0f0bddbd65c05348c43f
4
- data.tar.gz: be4975b3e283ae1f0d41b12dd78aab644b08597f4ad0e8db116db915436dbe8a
3
+ metadata.gz: 0225dfb974d2359199c76c94460e587943f1b8cf4313c9ef13bcc41e70ea9103
4
+ data.tar.gz: af50fa9455394d2c4b4d54751eba728c2f523f3f585e00133257615cdc430c87
5
5
  SHA512:
6
- metadata.gz: 836883d1772fe8ecfcf8af6bc07408d76a02b897b61ecec43f8843315f68dc457ec5158bc6da902388ec78f14d4978e500b8efdfd697ec5adfca80225408e012
7
- data.tar.gz: 1820d0b7fe2b16094292be981c32cf2cda644c34afe5f04b799f46b7c79783de099c3b29be8d94ff7dcd70eb5c1630ef20abbf4aed999df3d497aa852883946d
6
+ metadata.gz: 45ec1a5193dff2631e2a02416d0702ebd083e5a540203d6712b0630f87b6ef375776e4270bceccd13baf3e60273ea88b81b9d59b0f22989e17530f9d99f6a99a
7
+ data.tar.gz: 14ecae14c7e882f37bbe6d85a7880e3e6d5c18a969eeb5d6c6ed2098139cb1a5ccb661981a7802376cf6a6e890acd2fa0fc6da8e856009bc0313235a06a96748
@@ -67,6 +67,41 @@ module GetUrl
67
67
  return File.join(@sources_path, "#{id}.yaml")
68
68
  end
69
69
 
70
+ # Returns the path of the all-items-cache file.
71
+ #
72
+ # @return [String] The path of the all-items-cache file.
73
+ def get_all_items_cache_file
74
+ File.join(Dir.home, '.geturl', 'all-items-cache.yaml')
75
+ end
76
+
77
+ # Returns true if the all-items-cache file exists.
78
+ #
79
+ # @return [TrueClass|FalseClass]
80
+ def all_items_cache_exist?
81
+ return File.exists?(get_all_items_cache_file)
82
+ end
83
+
84
+ # Cache the given items to the all-items-cache.
85
+ #
86
+ # @param [Object] items
87
+ def cache_all_items(items)
88
+ save_items_to_yaml_file(items, get_all_items_cache_file)
89
+ end
90
+
91
+ # Returns all items from the all-items-cache.
92
+ #
93
+ # @return [Object] The items
94
+ def get_all_items_from_cache
95
+ return load_items_from_yaml_file(get_all_items_cache_file)
96
+ end
97
+
98
+ # Clears the all-items-cache.
99
+ #
100
+ # @return [Object]
101
+ def clear_all_items_cache
102
+ unlink(get_all_items_cache_file) if all_items_cache_exist?
103
+ end
104
+
70
105
  end
71
106
 
72
107
  end
@@ -25,12 +25,20 @@ module GetUrl
25
25
  # Loads all the given source ids. If ids is empty, all sources will be loaded.
26
26
  # @param [Array] ids An array of source ids.
27
27
  def load_sources(ids = nil)
28
- ids = Sources.get_sources.keys + ['local'] if ids.nil? || ids.empty?
29
28
  @items.clear
29
+
30
+ all_sources = (ids.nil? || ids.empty?)
31
+ if (all_sources) && (FileManager.all_items_cache_exist?)
32
+ @items = FileManager.get_all_items_from_cache
33
+ return
34
+ end
35
+
36
+ ids = Sources.get_sources.keys + ['local'] if ids.nil? || ids.empty?
30
37
  load_source(LocalUrls.private_source_id) if ids.include?('local')
31
38
  Sources.get_sources.keys.each {|id|
32
39
  load_source(id) if ids.include?(id)
33
40
  }
41
+ FileManager.cache_all_items(@items) if all_sources
34
42
  end
35
43
 
36
44
  # Returns all urls of the given ids. If ids is empty, all urls of all sources will be loaded.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geturl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taco Jan Osinga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-01 00:00:00.000000000 Z
11
+ date: 2018-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize