Class: MaintenanceMode::FilePersistence

Inherits:
Object
  • Object
show all
Defined in:
lib/maintenance_mode/file_persistence.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pathname) ⇒ FilePersistence

Returns a new instance of FilePersistence.



3
4
5
# File 'lib/maintenance_mode/file_persistence.rb', line 3

def initialize(pathname)
  @pathname = pathname
end

Instance Attribute Details

#pathnameObject (readonly)

Returns the value of attribute pathname.



7
8
9
# File 'lib/maintenance_mode/file_persistence.rb', line 7

def pathname
  @pathname
end

Instance Method Details

#disableObject



17
18
19
20
# File 'lib/maintenance_mode/file_persistence.rb', line 17

def disable
  return unless enabled?
  @pathname.unlink
end

#enable(message = '') ⇒ Object



13
14
15
# File 'lib/maintenance_mode/file_persistence.rb', line 13

def enable(message='')
  @pathname.write(message)
end

#enabled?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/maintenance_mode/file_persistence.rb', line 9

def enabled?
  @pathname.file?
end

#messageObject



22
23
24
25
26
# File 'lib/maintenance_mode/file_persistence.rb', line 22

def message
  return unless enabled?
  contents = @pathname.read.to_s
  contents == '' ? nil : contents
end