module Stacks_json

This module is part of class Drupal_Clusting, handles the stack_name => stack_url connection by means of a json file and the hash @stack.

Private Instance Methods

previous() click to toggle source

Gives back the last stack_name of the hash/json

# File lib/etc/stacks_json.rb, line 11
def previous
  name, url = @stacks.to_a.last
  name
end
put_at_the_end(stack_name) click to toggle source

Effectively puts the given stack_name at the end of both the hash and the .json file.

# File lib/etc/stacks_json.rb, line 38
def put_at_the_end stack_name
  @stacks.delete stack_name
  @stacks[stack_name] = nil 
  write_stacks_json
end
read_stacks_json() click to toggle source

Reads the json file into @stacks. In case of errors, it's quietly set to empty.

# File lib/etc/stacks_json.rb, line 19
def read_stacks_json
  @stacks = JSON.load File.new @@stacks_file
rescue SystemCallError # most probably: no such file yet
  @stacks = {}
end
write_stacks_json() click to toggle source

Writes the hash @stacks into the json file. In case of errors, argumentless functionality won't work.

# File lib/etc/stacks_json.rb, line 28
def write_stacks_json
  File.open(@@stacks_file, 'w') { |f|
    JSON.dump(@stacks, f)
  }
rescue SystemCallError
end