Class: HmxClient::Command::Dump

Inherits:
Base
  • Object
show all
Defined in:
lib/hmx/command/dump.rb

Overview

Dump data from a type in hmx and load it back again

Constant Summary

Constants inherited from Base

Base::FILE

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#hmx, #initialize, #loadConfig!, namespace, #removeConfig, #storeConfig, #writeConfig

Methods included from Helpers

#display, #display_row, #display_tab, #display_table, #error, #getFromUser, #longest

Constructor Details

This class inherits a constructor from HmxClient::Command::Base

Instance Method Details

#indexObject

dump

Dump data from hmx into the local filesystem. Used as a preface to a backup, or a change then restore

<typeName> <folderPath>



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hmx/command/dump.rb', line 15

def index
  unless args.size > 0
    raise CommandFailed, "Usage: hmx dump <typeName> <folderPath>"
  end
  # The filenames will come from the name of the type and their displayName, appended onto 
  # the folder path given. We will also attempt to create the folder path and the type
  # sub folder 
  typeName = args.shift
  rootFolder = args.shift
 
  Dir.mkdir(rootFolder) if !Dir.exist?(rootFolder)
  Dir.mkdir(rootFolder + "/" + typeName) if !Dir.exist?(rootFolder + "/" + typeName)
  displayNames = hmx.doQuery([typeName, nil])
  displayNames.each { | displayName | 
                    fileName = rootFolder + "/" + displayName
                    display "Writing to #{ fileName }"
                    File.open(fileName, 'w') { | f | f.write(JSON.pretty_generate(hmx.doGetData([displayName]))) }
                    } 
end

#loadObject

dump:load

Load data that has previously been dumped using the main dump command

<typeName> <folderPath>

The real path for the files is in the folder formed by concatenating the typename to the rootFolder



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hmx/command/dump.rb', line 42

def load
 unless args.size > 0
   raise CommandFailed, "Usage: hmx dump:load <typeName> <folderPath>"
 end
 typeName = args.shift
 rootFolder = args.shift

 folderName = rootFolder + "/" + typeName
 Dir.foreach(folderName) { | f | 
                              display "Loading #{ f } "
                              fullFile = folderName + "/" + f
                              if (File.file?(fullFile)) 
                                 content = File.open(fullFile) { | h | 
	c = '';
	while(line = h.gets) 
		c = c + line
	end
        c
                                           }
                                 puts "Content is #{ content } "
                                 hmx.doPutData([content])	
                              end
                           }
end