Module: CVTool

Defined in:
lib/cv_tool.rb,
lib/cv_tool/os.rb,
lib/cv_tool/http.rb,
lib/cv_tool/event.rb,
lib/cv_tool/files.rb,
lib/cv_tool/version.rb,
lib/cv_tool/rest_api.rb,
lib/cv_tool/constants.rb

Defined Under Namespace

Modules: Constants, Event, Files, Http, OS, RestApi

Constant Summary collapse

VERSION =
'1.0.2'

Class Method Summary collapse

Class Method Details

.generate_db(args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cv_tool.rb', line 20

def generate_db(args)
  name_dir = args[:endpoint].sub('get/', '')
  absolute_path_dir = File.expand_path(name_dir, args[:path])
  contents = args[:response]

  contents.each.with_index do |c, i|
    content = c.delete_if do |k, _|
      k == :id.to_s or k == :created_at.to_s or k == :last_change.to_s
    end
    name_file = "#{ name_dir.sub(/s$/, '') }_#{i + 1}.json"
    absolute_path_file = File.join(absolute_path_dir, name_file)
    json = JsonParser.new(absolute_path_file)

    content.each do |k, v|
      json.parse(k, v)
    end
    CVTool::Event.print('GENERATE', absolute_path_file)
  end
end

.generate_token(length = Constants::GT_LENGTH) ⇒ Object



14
15
16
17
18
# File 'lib/cv_tool.rb', line 14

def generate_token(length = Constants::GT_LENGTH)
  chars = Array('A'..'Z') + Array('a'..'z') + Array(0..9)
  token = Array.new(length) { chars.sample }.join
  return token
end

.setup_db(path) ⇒ Object



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
# File 'lib/cv_tool.rb', line 40

def setup_db(path)
  dir_apath = File.join(path, '*/*.json')
  json_files = Dir.glob(dir_apath)
  files = {
    articles: json_files.select { |e| e.index(/\/articles\//) },
    projects: json_files.select { |e| e.index(/\/projects\//) },
  }
  
  h_execute_command = lambda do |symbol|
    result = ""
    files[symbol].each.with_index do |path, i|
      result += "#{ROOT_FILE} -ra -ep post/#{symbol.to_s.sub(/s$/, '')}/add -reb #{path} &&\n"
    end
    return result
  end

  command = h_execute_command.call(:projects) + h_execute_command.call(:articles)
  is_success = system(command.sub(/ &&\n$/, "\n"))

  if is_success
    CVTool::Event.print('SETUP-DB', "done")
  else
    CVTool::Event.print('SETUP-DB', "an error occurred during db setup.")
  end
end