Class: Ellipses::Client::MetaFile
- Inherits:
-
Object
- Object
- Ellipses::Client::MetaFile
- Defined in:
- lib/ellipses/client/meta_file.rb
Constant Summary collapse
- FILES =
%w[.local/etc/src.lock src.lock .src.lock].freeze
- EMPTY =
"[]\n"
Instance Attribute Summary collapse
-
#alternatives ⇒ Object
readonly
Returns the value of attribute alternatives.
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
Class Method Summary collapse
Instance Method Summary collapse
- #file ⇒ Object
-
#initialize ⇒ MetaFile
constructor
A new instance of MetaFile.
- #loaded! ⇒ Object
- #loaded? ⇒ Boolean
- #read ⇒ Object
- #to_s ⇒ Object
- #write(meta) ⇒ Object
Constructor Details
#initialize ⇒ MetaFile
Returns a new instance of MetaFile.
24 25 26 |
# File 'lib/ellipses/client/meta_file.rb', line 24 def initialize @directory, @file = Support.search_path FILES end |
Instance Attribute Details
#alternatives ⇒ Object (readonly)
Returns the value of attribute alternatives.
22 23 24 |
# File 'lib/ellipses/client/meta_file.rb', line 22 def alternatives @alternatives end |
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
22 23 24 |
# File 'lib/ellipses/client/meta_file.rb', line 22 def directory @directory end |
Class Method Details
.create(directory) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ellipses/client/meta_file.rb', line 11 def self.create(directory) Support.dir!(directory) selected = FILES.find { |path| ::Dir.exist? File.join(directory, ::File.dirname(path)) } file = ::File.join(directory, selected) ::File.write(file, EMPTY) unless ::File.exist? file new end |
Instance Method Details
#file ⇒ Object
28 29 30 31 |
# File 'lib/ellipses/client/meta_file.rb', line 28 def file loaded! @file end |
#loaded! ⇒ Object
37 38 39 40 41 |
# File 'lib/ellipses/client/meta_file.rb', line 37 def loaded! raise 'Lockfile not located' if @file.nil? raise "Lockfile not found: #{@file}" unless ::File.exist? @file end |
#loaded? ⇒ Boolean
33 34 35 |
# File 'lib/ellipses/client/meta_file.rb', line 33 def loaded? @file && ::File.exist?(@file) end |
#read ⇒ Object
43 44 45 |
# File 'lib/ellipses/client/meta_file.rb', line 43 def read Meta.from_array JSON.load_file(file, symbolize_names: true) end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/ellipses/client/meta_file.rb', line 51 def to_s file end |
#write(meta) ⇒ Object
47 48 49 |
# File 'lib/ellipses/client/meta_file.rb', line 47 def write() Support.updatelines(file, .empty? ? EMPTY : JSON.pretty_generate()) end |