Class: AutoConsul::Local::FileSystemState
- Inherits:
-
Object
- Object
- AutoConsul::Local::FileSystemState
- Defined in:
- lib/auto-consul/local.rb
Constant Summary collapse
- VALID_MODES =
{ 'agent' => 'agent', 'server' => 'server', }
Class Method Summary collapse
Instance Method Summary collapse
- #agent? ⇒ Boolean
- #data_path ⇒ Object
-
#initialize(path) ⇒ FileSystemState
constructor
A new instance of FileSystemState.
- #mode ⇒ Object
- #mode_path ⇒ Object
- #path ⇒ Object
- #server? ⇒ Boolean
- #set_agent! ⇒ Object
- #set_mode(mode) ⇒ Object
- #set_server! ⇒ Object
Constructor Details
#initialize(path) ⇒ FileSystemState
Returns a new instance of FileSystemState.
6 7 8 9 10 11 12 |
# File 'lib/auto-consul/local.rb', line 6 def initialize path unless File.directory? path FileUtils.mkdir_p path end @path = path end |
Class Method Details
.determine_mode(mode_file) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/auto-consul/local.rb', line 41 def self.determine_mode mode_file if File.file? mode_file value = File.open(mode_file, 'r') {|f| f.read } VALID_MODES[value] else nil end end |
Instance Method Details
#agent? ⇒ Boolean
61 62 63 |
# File 'lib/auto-consul/local.rb', line 61 def agent? mode == 'agent' end |
#data_path ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/auto-consul/local.rb', line 65 def data_path if not (m = mode).nil? File.join(path, mode) else nil end end |
#mode ⇒ Object
50 51 52 53 54 55 |
# File 'lib/auto-consul/local.rb', line 50 def mode if @mode.nil? @mode = self.class.determine_mode mode_path end @mode end |
#mode_path ⇒ Object
18 19 20 |
# File 'lib/auto-consul/local.rb', line 18 def mode_path File.join(path, 'mode') end |
#path ⇒ Object
14 15 16 |
# File 'lib/auto-consul/local.rb', line 14 def path @path end |
#server? ⇒ Boolean
57 58 59 |
# File 'lib/auto-consul/local.rb', line 57 def server? mode == 'server' end |
#set_agent! ⇒ Object
26 27 28 |
# File 'lib/auto-consul/local.rb', line 26 def set_agent! set_mode 'agent' end |
#set_mode(mode) ⇒ Object
30 31 32 33 34 |
# File 'lib/auto-consul/local.rb', line 30 def set_mode mode File.open(mode_path, 'w') do |f| f.write mode end end |
#set_server! ⇒ Object
22 23 24 |
# File 'lib/auto-consul/local.rb', line 22 def set_server! set_mode 'server' end |