Class: HmxClient::Command::Check

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

Overview

Provides the ability to check view functions locally

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

#checkSaveObject

check:save

Given a check function, runs that function against all documents, outputting the value If the third parameter is given that is an option, to pick one doc (ONE), just display part PART, or FULL for everything.

<folder> <fnName> <typeName> [ONE|PART|FULL]



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/hmx/command/check.rb', line 55

def checkSave
  unless args.size > 1
    raise CommandFailed, 'Usage: hmx check:save <folderName> <checkfn> <typeName> <ONE|PART|FULL>'
  end
  @rootFolder = args.shift
  fnName = args.shift
  typeName = args.shift
  option = 'FULL'
  if args.size > 0
   option = args.shift
  end 

  # What we do here is this
  # Create an eval string of
  # 
  content = getFn(fnName)
  Evaluator.class_eval(content)

  # Now get the data object
  typeFolder = "#{@rootFolder}/#{typeName}"
  ev = Evaluator.new(@rootFolder)
  res = []
  Dir.foreach(typeFolder) { | f |
       display "Testing #{f}"
              fullFile = File.expand_path("#{typeFolder}/#{f}")
              if (File.file?(fullFile))  
                      data = getData(fullFile)
 	                  res << ev.check(data) 
              end
  }
  display_tab(res)
end

#checkViewObject

check:view

Given a folder, a type, a filter fn and a map fn, and a set of parameters to the view run the view “locally” in this environment, by evaluating the filter and map against each document downloaded for the type



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/hmx/command/check.rb', line 93

def checkView
  unless args.size > 3
    raise CommandFailed, "Usage: hmx check:view <folderName> <typeName> <filter> <map> <paramString>"
  end
  @rootFolder = args.shift
  typeName = args.shift
  filterFn = args.shift
  mapFn = args.shift
  paramString = args.shift
  paramString = JSON.parse(paramString)

  filterContent = getFn(filterFn)
  mapContent = getFn(mapFn)
  Evaluator.class_eval(filterContent)
  Evaluator.class_eval(mapContent)
  ev = Evaluator.new(@rootFolder)
  res = []
  typeFolder = "#{@rootFolder}/#{typeName}/"
  Dir.foreach(typeFolder) { | f |
              fullFile = File.expand_path("#{typeFolder}/#{f}")
              if (File.file?(fullFile))  
                      data = getData(fullFile)
 	                  val = ev.runView(data, paramString) 
                      if (!val.nil?)
                         res << val
                      end
              end
  }
  display_tab res
end

#indexObject

check

Download an environment to check <folderName> <type>

Creates <folderName>/functions/[function files that are Ruby] And <folderName>/<typeName>/[files corresponding to the documents in that type]



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hmx/command/check.rb', line 17

def index
  unless args.size > 1 
    raise CommandFailed, "Usage: hmx check <folderName> <typeName>" 
  end
  rootFolder = args.shift;
  typeName = args.shift;
  Dir.mkdir(rootFolder) if !Dir.exist?(rootFolder)
  fnFolder = rootFolder + '/function/'
  Dir.mkdir(fnFolder) if !Dir.exist?(fnFolder)
  displayNames = hmx.doQuery(['sys.fn',nil])
  displayNames.each { | displayName | 
          fnInfo = hmx.doGetData([displayName])
          if fnInfo['document']['MXFunction']['fnLang'] == 'RUBY'
             puts "Writing function  - #{ displayName }"
             outfile = fnFolder + fnInfo['document']['MXFunction']['fnName'] + '.rb'
             File.open(outfile, 'w') { | f | f.write(fnInfo['document']['MXFunction']['content']) }  
          end
  }
 # Now do types
 typeFolder = rootFolder + '/' + typeName
 Dir.mkdir(typeFolder) if !Dir.exist?(typeFolder)
 displayNames = hmx.doQuery([typeName, nil])
 displayNames.each { | displayName | 
           document = hmx.doGetData([displayName])
           outfile = rootFolder + '/' + displayName
           puts "Writing #{ typeName } - #{ displayName }"
           File.open(outfile, 'w') { | f | f.write(JSON.pretty_generate(document)) }
 } 
end