Class: Arli::Lock::File

Inherits:
Object
  • Object
show all
Defined in:
lib/arli/lock/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#arlifileObject

Returns the value of attribute arlifile.



12
13
14
# File 'lib/arli/lock/file.rb', line 12

def arlifile
  @arlifile
end

#configObject

Returns the value of attribute config.



12
13
14
# File 'lib/arli/lock/file.rb', line 12

def config
  @config
end

#fileObject

Returns the value of attribute file.



12
13
14
# File 'lib/arli/lock/file.rb', line 12

def file
  @file
end

#formatObject

Returns the value of attribute format.



12
13
14
# File 'lib/arli/lock/file.rb', line 12

def format
  @format
end

#formatterObject

Returns the value of attribute formatter.



12
13
14
# File 'lib/arli/lock/file.rb', line 12

def formatter
  @formatter
end

#lock_file_pathObject

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

#closeObject



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.footer)
ensure
  close
end

#lock!(*args) ⇒ Object



38
39
40
# File 'lib/arli/lock/file.rb', line 38

def lock!(*args)
  lock(*args)
end