Module: Insta::PendingLocations
- Defined in:
- lib/insta/pending_locations.rb,
sig/insta/pending_locations.rbs
Constant Summary collapse
- FILENAME =
".insta-pending-locations"
Class Method Summary collapse
-
.add(path, caller_line) ⇒ void
: (String, String) -> void.
-
.clean! ⇒ void
: () -> void.
-
.clear! ⇒ void
: () -> void.
-
.flush! ⇒ void
: () -> void.
-
.load ⇒ Hash[String, String]
: () -> Hash[String, String].
Class Method Details
.add(path, caller_line) ⇒ void
This method returns an undefined value.
: (String, String) -> void
13 14 15 16 17 |
# File 'lib/insta/pending_locations.rb', line 13 def self.add(path, caller_line) @mutex.synchronize do @locations[path] = caller_line end end |
.clean! ⇒ void
This method returns an undefined value.
: () -> void
53 54 55 56 57 |
# File 'lib/insta/pending_locations.rb', line 53 def self.clean! manifest_path = File.join(Insta.configuration.snapshot_path, FILENAME) FileUtils.rm_f(manifest_path) end |
.clear! ⇒ void
This method returns an undefined value.
: () -> void
60 61 62 |
# File 'lib/insta/pending_locations.rb', line 60 def self.clear! @mutex.synchronize { @locations.clear } end |
.flush! ⇒ void
This method returns an undefined value.
: () -> void
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/insta/pending_locations.rb', line 20 def self.flush! entries = @mutex.synchronize do result = @locations.dup @locations.clear result end return if entries.empty? manifest_path = File.join(Insta.configuration.snapshot_path, FILENAME) existing = if File.exist?(manifest_path) JSON.parse(File.read(manifest_path)) else {} #: Hash[String, String] end existing.merge!(entries) FileUtils.mkdir_p(File.dirname(manifest_path)) File.write(manifest_path, JSON.pretty_generate(existing)) end |
.load ⇒ Hash[String, String]
: () -> Hash[String, String]
43 44 45 46 47 48 49 50 |
# File 'lib/insta/pending_locations.rb', line 43 def self.load manifest_path = File.join(Insta.configuration.snapshot_path, FILENAME) return {} unless File.exist?(manifest_path) JSON.parse(File.read(manifest_path)) rescue JSON::ParserError {} end |