Class: Arli::Lock::File
- Inherits:
-
Object
- Object
- Arli::Lock::File
- Defined in:
- lib/arli/lock/file.rb
Instance Attribute Summary collapse
-
#arlifile ⇒ Object
Returns the value of attribute arlifile.
-
#config ⇒ Object
Returns the value of attribute config.
-
#file ⇒ Object
Returns the value of attribute file.
-
#format ⇒ Object
Returns the value of attribute format.
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#lock_file_path ⇒ Object
Returns the value of attribute lock_file_path.
Instance Method Summary collapse
- #append(line = nil) ⇒ Object
- #close ⇒ Object
-
#initialize(config: Arli.config, arlifile: nil) ⇒ File
constructor
A new instance of File.
- #lock(*libraries) ⇒ Object
- #lock!(*args) ⇒ Object
Constructor Details
#initialize(config: Arli.config, arlifile: nil) ⇒ File
Returns a new instance of File.
19 20 21 22 23 24 25 26 |
# File 'lib/arli/lock/file.rb', line 19 def initialize(config: Arli.config, arlifile: nil) self.config = config self.arlifile = arlifile self.format = config.arlifile.lock_format self.formatter = set_formatter(format) self.lock_file_path = "#{config.arlifile.path}/#{config.arlifile.name}.#{formatter.extension}" self.file = ::File.open(lock_file_path, 'w') end |
Instance Attribute Details
#arlifile ⇒ Object
Returns the value of attribute arlifile.
12 13 14 |
# File 'lib/arli/lock/file.rb', line 12 def arlifile @arlifile end |
#config ⇒ Object
Returns the value of attribute config.
12 13 14 |
# File 'lib/arli/lock/file.rb', line 12 def config @config end |
#file ⇒ Object
Returns the value of attribute file.
12 13 14 |
# File 'lib/arli/lock/file.rb', line 12 def file @file end |
#format ⇒ Object
Returns the value of attribute format.
12 13 14 |
# File 'lib/arli/lock/file.rb', line 12 def format @format end |
#formatter ⇒ Object
Returns the value of attribute formatter.
12 13 14 |
# File 'lib/arli/lock/file.rb', line 12 def formatter @formatter end |
#lock_file_path ⇒ Object
Returns the value of attribute lock_file_path.
12 13 14 |
# File 'lib/arli/lock/file.rb', line 12 def lock_file_path @lock_file_path end |
Instance Method Details
#append(line = nil) ⇒ Object
46 47 48 49 |
# File 'lib/arli/lock/file.rb', line 46 def append(line = nil) return unless line line.end_with?("\n") ? file.print(line) : file.puts(line) end |
#close ⇒ Object
42 43 44 |
# File 'lib/arli/lock/file.rb', line 42 def close file.close rescue nil end |
#lock(*libraries) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/arli/lock/file.rb', line 28 def lock(*libraries) append(formatter.header) libraries.each do |lib| append(formatter.format(lib)) end append(formatter.) ensure close end |
#lock!(*args) ⇒ Object
38 39 40 |
# File 'lib/arli/lock/file.rb', line 38 def lock!(*args) lock(*args) end |