Class: Capistrano::DeployLocker::Provider
- Inherits:
-
Object
- Object
- Capistrano::DeployLocker::Provider
- Defined in:
- lib/capistrano/deploy_locker/provider.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #create ⇒ Object
- #info ⇒ Object
-
#initialize(config = Capistrano::DeployLocker.config) ⇒ Provider
constructor
A new instance of Provider.
- #locked? ⇒ Boolean
- #update_info ⇒ Object
Constructor Details
#initialize(config = Capistrano::DeployLocker.config) ⇒ Provider
Returns a new instance of Provider.
4 5 6 7 |
# File 'lib/capistrano/deploy_locker/provider.rb', line 4 def initialize(config = Capistrano::DeployLocker.config) @config = config FileUtils.mkpath(config.lock_dir) end |
Instance Method Details
#clear ⇒ Object
32 33 34 35 |
# File 'lib/capistrano/deploy_locker/provider.rb', line 32 def clear @lock_file.flock(File::LOCK_UN | File::LOCK_NB) @lock_file.close end |
#create ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/capistrano/deploy_locker/provider.rb', line 17 def create @lock_file = File.open(lock_file, File::RDWR | File::CREAT, 0o0644) unless @lock_file.flock(File::LOCK_EX | File::LOCK_NB) @lock_file.close = "#{lock_file} is already locked!\n" if i = info << "Info: #{i}" else << 'No additional info available.' end raise Capistrano::DeployLocker::AlreadyLocked, end update_info end |
#info ⇒ Object
37 38 39 40 |
# File 'lib/capistrano/deploy_locker/provider.rb', line 37 def info return unless File.readable?(info_file) JSON.parse(File.read(info_file)) end |
#locked? ⇒ Boolean
9 10 11 12 13 14 15 |
# File 'lib/capistrano/deploy_locker/provider.rb', line 9 def locked? locked = false File.open(lock_file, File::RDWR | File::CREAT, 0o0644) do |f| locked = true unless f.flock(File::LOCK_EX | File::LOCK_NB) end locked end |
#update_info ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/capistrano/deploy_locker/provider.rb', line 42 def update_info content = { user: @config.who, reason: @config.why, date: Time.now, }.to_json File.write(info_file, "#{content}\n") end |