foobara-cached-command 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
  SHA256:
3
- metadata.gz: c36cb25ec47a00d8754634b857722e8eb4e547fb257fa537876a7886ba93fa3a
4
- data.tar.gz: 5443d74e0926fe9d769b8c371d45888d2e47cd0abcbf48a633d17b81481579bc
3
+ metadata.gz: 28d9ff865e9bcef1916074da6800fc794ccd1be7b476eabb0eae805cd30fd927
4
+ data.tar.gz: 06c371633bde1bd493a2ba945a0b68665d761a4ce13c281cb1e45532b9ca0ec3
5
5
  SHA512:
6
- metadata.gz: 8e406d4e36b5758e844eb24432ea4382f7ff993ea8c62e2a58d2cc01a72d7d6478ea3e750b30ce68e6bc03d9bad60b46c44b4ddf71fb297d52b1c4ce8d279f6f
7
- data.tar.gz: 30e2d6bdc35f1278bebee5a28a8b687fcd0359ac0724ebb45cf23a95f15e2f95e0071f1fd6e64464a0c66df41d622bc9e1f085f6dc96fc7b75b6d68e76b05d1e
6
+ metadata.gz: 8a85959c4074b29c67df622245572ffbf1842d4d5439f8bbf92b42be73ab286c595f86c5f0ef878ca3b67b4a06160facd9c6e91274a4f1de084d6e7b91f761b3
7
+ data.tar.gz: 8ff108e33e8c3b63e519595763e36dda8e82c9d8a3830cdfb63317c8cba04b94febd54762cdf94c42a34169176c18241328a8b8ee19db5712280c50acfd167d5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [0.0.2] - 2025-02-19
2
+
3
+ - Fix bugs with tmp file name
4
+ - Fix bugs when not using an expiry
5
+ - Give a flag to disable caching entirely
6
+
1
7
  ## [0.0.1]
2
8
 
3
9
  - Release as a gem
@@ -15,17 +15,22 @@ module Foobara
15
15
  unless data
16
16
  if File.exist?(file_path)
17
17
  data = Util.symbolize_keys(JSON.parse(File.read(file_path)))
18
- data[:expires_at] = Time.parse(data[:expires_at])
19
- cache[key] = data
18
+
19
+ if data.key?(:expires_at)
20
+ data[:expires_at] = Time.parse(data[:expires_at])
21
+ cache[key] = data
22
+ end
20
23
  else
21
24
  return nil
22
25
  end
23
26
  end
24
27
 
25
- if Time.now > data[:expires_at]
26
- cache.delete(key)
27
- FileUtils.rm_f(file_path)
28
- data = nil
28
+ if data.key?(:expires_at)
29
+ if Time.now > data[:expires_at]
30
+ cache.delete(key)
31
+ FileUtils.rm_f(file_path)
32
+ data = nil
33
+ end
29
34
  end
30
35
 
31
36
  data
@@ -40,13 +45,20 @@ module Foobara
40
45
  data[:expires_at] = created_at + expiry
41
46
  end
42
47
 
48
+ basedir = File.dirname(file_path)
49
+
50
+ FileUtils.mkdir_p(basedir)
51
+
43
52
  File.write(file_path, JSON.fast_generate(data))
44
53
  cache[key] = data
45
54
  end
46
55
  end
47
56
 
57
+ # We need to prepend this so that we're overriding the method defined in the class we're mixed into
48
58
  module Execute
49
59
  def execute
60
+ return super if foobara_cache_disabled
61
+
50
62
  if foobara_cached_value_present?
51
63
  foobara_cached_value
52
64
  else
@@ -60,7 +72,8 @@ module Foobara
60
72
  include Concern
61
73
 
62
74
  inherited_overridable_class_attr_accessor :foobara_cache_expiry,
63
- :foobara_cache_serializer
75
+ :foobara_cache_serializer,
76
+ :foobara_cache_disabled
64
77
 
65
78
  on_include do
66
79
  prepend Execute
@@ -83,7 +96,7 @@ module Foobara
83
96
 
84
97
  # TODO: support various caching strategies like memcached or redis, not just local files
85
98
  def foobara_cache_path
86
- "tmp/#{foobara_cache_key}.json"
99
+ @foobara_cache_path ||= "tmp/cached_command/#{foobara_cache_key}.json".gsub("::", "/")
87
100
  end
88
101
 
89
102
  # TODO: support caching based on certain inputs...
@@ -121,5 +134,9 @@ module Foobara
121
134
  def foobara_cache_expiry
122
135
  self.class.foobara_cache_expiry
123
136
  end
137
+
138
+ def foobara_cache_disabled
139
+ self.class.foobara_cache_disabled
140
+ end
124
141
  end
125
142
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-cached-command
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
  - Miles Georgi