Module: SycLink::Infrastructure

Included in:
Designer
Defined in:
lib/syclink/infrastructure.rb

Overview

Helper methods to setup the infrastructure for syclink

Instance Method Summary collapse

Instance Method Details

#copy_file_if_missing(file, to_directory) ⇒ Object

Copies a file to a target directory



15
16
17
18
19
# File 'lib/syclink/infrastructure.rb', line 15

def copy_file_if_missing(file, to_directory)
  unless File.exists? File.join(to_directory, File.basename(file))
    FileUtils.cp(file, to_directory)
  end
end

#create_directory_if_missing(directory) ⇒ Object

Creates a directory if it does not exist



8
9
10
11
12
# File 'lib/syclink/infrastructure.rb', line 8

def create_directory_if_missing(directory)
  unless File.exists? directory
    Dir.mkdir directory
  end
end

#html_file(directory = '.', website) ⇒ Object

Creates an html filename to save the html representation of the website to



38
39
40
# File 'lib/syclink/infrastructure.rb', line 38

def html_file(directory = '.', website)
  File.join(directory, "#{website.downcase.gsub(/\s/, '-')}.html")
end

#load_config(file) ⇒ Object

Loads the configuration from a file



22
23
24
25
26
27
28
29
# File 'lib/syclink/infrastructure.rb', line 22

def load_config(file)
  unless File.exists? file
    File.open(file, 'w') do |f| 
      YAML.dump({ default_website: 'default' }, f) 
    end
  end
  YAML.load_file(file)
end

#yaml_file(directory = '.', website) ⇒ Object

Creates the filename of the website for saving, loading and deleting



32
33
34
# File 'lib/syclink/infrastructure.rb', line 32

def yaml_file(directory = '.', website)
  File.join(directory, "#{website.downcase.gsub(/\s/, '-')}.website")
end