class Turnout::MaintenanceFile
Constants
- SETTINGS
Attributes
path[R]
Public Class Methods
default()
click to toggle source
# File lib/turnout/maintenance_file.rb, line 70 def self.default self.new(named_paths.values.first) end
find()
click to toggle source
Find the first MaintenanceFile
that exists
# File lib/turnout/maintenance_file.rb, line 60 def self.find path = named_paths.values.find { |p| File.exist? p } self.new(path) if path end
named(name)
click to toggle source
# File lib/turnout/maintenance_file.rb, line 65 def self.named(name) path = named_paths[name.to_sym] self.new(path) unless path.nil? end
new(path)
click to toggle source
# File lib/turnout/maintenance_file.rb, line 11 def initialize(path) @path = path @reason = Turnout.config.default_reason @allowed_paths = Turnout.config.default_allowed_paths @allowed_ips = Turnout.config.default_allowed_ips @response_code = Turnout.config.default_response_code @retry_after = Turnout.config.default_retry_after import_yaml if exists? end
Private Class Methods
named_paths()
click to toggle source
# File lib/turnout/maintenance_file.rb, line 115 def self.named_paths Turnout.config.named_maintenance_file_paths end
Public Instance Methods
delete()
click to toggle source
# File lib/turnout/maintenance_file.rb, line 46 def delete File.delete(path) if exists? end
exists?()
click to toggle source
# File lib/turnout/maintenance_file.rb, line 22 def exists? File.exist? path end
import(hash)
click to toggle source
# File lib/turnout/maintenance_file.rb, line 50 def import(hash) SETTINGS.map(&:to_s).each do |att| self.send(:"#{att}=", hash[att]) unless hash[att].nil? end true end
Also aliased as: import_env_vars
to_h()
click to toggle source
# File lib/turnout/maintenance_file.rb, line 26 def to_h SETTINGS.each_with_object({}) do |att, hash| hash[att] = send(att) end end
to_yaml(key_mapper = :to_s)
click to toggle source
# File lib/turnout/maintenance_file.rb, line 32 def to_yaml(key_mapper = :to_s) to_h.each_with_object({}) { |(key, val), hash| hash[key.send(key_mapper)] = val }.to_yaml end
write()
click to toggle source
# File lib/turnout/maintenance_file.rb, line 38 def write FileUtils.mkdir_p(dir_path) unless Dir.exist? dir_path File.open(path, 'w') do |file| file.write to_yaml end end
Private Instance Methods
allowed_ips=(ips)
click to toggle source
Splits strings on commas for easier importing of environment variables
# File lib/turnout/maintenance_file.rb, line 97 def allowed_ips=(ips) ips = ips.to_s.split(',') if ips.is_a? String @allowed_ips = ips end
allowed_paths=(paths)
click to toggle source
Splits strings on commas for easier importing of environment variables
# File lib/turnout/maintenance_file.rb, line 85 def allowed_paths=(paths) if paths.is_a? String # Grab everything between commas that aren't escaped with a backslash paths = paths.to_s.split(/(?<!\\),\ ?/).map do |path| path.strip.gsub('\,', ',') # remove the escape characters end end @allowed_paths = paths end
dir_path()
click to toggle source
# File lib/turnout/maintenance_file.rb, line 107 def dir_path File.dirname(path) end
import_yaml()
click to toggle source
# File lib/turnout/maintenance_file.rb, line 111 def import_yaml import YAML::load(File.open(path)) || {} end
reason=(reason)
click to toggle source
# File lib/turnout/maintenance_file.rb, line 80 def reason=(reason) @reason = reason.to_s end
response_code=(code)
click to toggle source
# File lib/turnout/maintenance_file.rb, line 103 def response_code=(code) @response_code = code.to_i end
retry_after=(value)
click to toggle source
# File lib/turnout/maintenance_file.rb, line 76 def retry_after=(value) @retry_after = value end