Class: Home

Inherits:
Object
  • Object
show all
Defined in:
lib/quartz_flow/home.rb

Overview

Class used to setup a new QuartzFlow home directory, and get information about it.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir = ".") ⇒ Home

Returns a new instance of Home.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/quartz_flow/home.rb', line 6

def initialize(dir = ".")
  @dir = dir

  @subdirs = [
    "etc",
    "log",
    "download",
    "meta",
    "public",
    "db",
    "views",
    "plugins",
  ]

  @installRoot = Home.determineAppRoot("quartz_flow")
end

Class Method Details

.determineAppRoot(gemname) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/quartz_flow/home.rb', line 70

def self.determineAppRoot(gemname)
  # Are we running as a Gem, or from the source directory?
  if Gem.loaded_specs[gemname]
    Gem.loaded_specs[gemname].full_gem_path
  else
    "."
  end
end

Instance Method Details

#setupObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/quartz_flow/home.rb', line 36

def setup
  @subdirs.each do |subdir|
    if File.directory?(subdir)
      puts "Directory #{subdir} already exists. Skipping creation."
    else
      installedPath = @installRoot + File::SEPARATOR + subdir 
      if File.directory? installedPath
        FileUtils.cp_r installedPath, @dir
        puts "Copying #{subdir}"
      else
        FileUtils.mkdir @dir + File::SEPARATOR + subdir
        puts "Creating #{subdir}"
      end
    end
  end

  # Create database
  dbFile = "#{File.expand_path(@dir)}/db/quartz.sqlite"
  if ! File.exists?(dbFile)
    puts "Creating database file"
    path = "sqlite://#{File.expand_path(@dir)}/db/quartz.sqlite"
    DataMapper.setup(:default, path)
    DataMapper.auto_migrate!
  else
    puts "Database file already exists. Running upgrade."
    path = "sqlite://#{File.expand_path(@dir)}/db/quartz.sqlite"
    DataMapper.setup(:default, path)
    DataMapper.auto_upgrade!
  end

  # Install plugins.
  setupPlugins
end

#validateObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/quartz_flow/home.rb', line 23

def validate
  rc = true
  @subdirs.each do |subdir|
    path = File.join(@dir, subdir)
    if ! File.directory?(path)
      puts "Error: The home directory is invalid: the subdirectory #{subdir} doesn't exist under the home directory. Was the setup command run?"
      rc = false
      break
    end
  end
  rc
end