Module: Projects::Methods

Included in:
App
Defined in:
lib/projects/methods.rb

Constant Summary

HVE_CONTENT_TYPE =
'application/vnd.perforce.project.hve.v1+json'
HVE_ID =
'hveProject'

Instance Method Summary (collapse)

Instance Method Details

- (Object) depot_path_for_name(name)



91
92
93
# File 'lib/projects/methods.rb', line 91

def depot_path_for_name(name)
  "#{hve_projects_path}/#{name}"
end

- (Object) encode_name(name)



79
80
81
# File 'lib/projects/methods.rb', line 79

def encode_name(name)
  HWSStrings.component_encode(name)
end

- (Object) fetch(id)

The ID is a URL encoded version of the directory name under HVE_PROJECTS_PATH.

This will unencode the ID and fetch by name.



50
51
52
53
54
55
56
57
58
59
# File 'lib/projects/methods.rb', line 50

def fetch(id)
  name = unencode_name(id)

  if !Cloud::Settings.cloud_enabled?
    return fetch_by_depot_dir_name(name)
  else
    projects_service = Cloud::Projects.new(env:@env)
    projects_service.fetch(id)
  end
end

- (Object) fetch_by_depot_dir_name(name)

Returns the project's “details” based on the project name.

No validation is done to ensure this directory actually exists in the system.



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/projects/methods.rb', line 65

def fetch_by_depot_dir_name(name)
  return nil if env['hws_settings'].HVE_PROJECTS_PATH.nil?
  id = encode_name(name)

  {
      'id': id,
      'name': name,
      'server': server_uri_for_id(id),
      HVE_ID => {
          'depotPath': depot_path_for_name(name)
      }
  }
end

- (Object) hve_projects_path



95
96
97
# File 'lib/projects/methods.rb', line 95

def hve_projects_path
  env['hws_settings'].HVE_PROJECTS_PATH || fail('HVE_PROJECTS_PATH not set')
end

- (Object) list(details: false, extension: nil)

List HVE Projects as configured in the system.

See the Appendix in the documentation for details on values.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/projects/methods.rb', line 13

def list(details: false, extension: nil)
  return if extension and (extension != HVE_ID or extension != HVE_CONTENT_TYPE)

  if Cloud::Settings.cloud_enabled?
    projects_service = Cloud::Projects.new(env:@env)
    return projects_service.list(details: details)
  end

  project_dirs = list_project_names
  project_names = project_dirs.map { |d| File.basename(d) }

  if details
    project_names.map { |n| fetch_by_depot_dir_name(n) }
  else
    project_names.map { |n| encode_name(n) }
  end
end

- (Object) list_project_names



31
32
33
34
35
36
37
38
# File 'lib/projects/methods.rb', line 31

def list_project_names
  if !Cloud::Settings.cloud_enabled?
    return list_project_names_onsite_impl
  else
    projects_service = Cloud::Projects.new(env:@env)
    return projects_service.list(false)
  end
end

- (Object) list_project_names_onsite_impl



40
41
42
43
44
# File 'lib/projects/methods.rb', line 40

def list_project_names_onsite_impl
  pattern = "#{hve_projects_path}/*"
  results = p4.run_dirs(pattern)
  results.map { |r| r['dir'] }
end

- (Object) p4host



131
132
133
# File 'lib/projects/methods.rb', line 131

def p4host
  env['hws_settings'].P4HOST
end

- (Object) p4port



127
128
129
# File 'lib/projects/methods.rb', line 127

def p4port
  env['hws_settings'].P4PORT || fail('P4PORT setting not available')
end

- (Object) safe_hve_projects_path



99
100
101
# File 'lib/projects/methods.rb', line 99

def safe_hve_projects_path
  hve_projects_path.gsub('//', '/')
end

- (Object) server



118
119
120
121
122
123
124
125
# File 'lib/projects/methods.rb', line 118

def server
  return p4port if p4port.include?(':')

  host = p4host ? p4host : 'localhost'
  port = p4port

  "#{host}:#{port}"
end

- (Object) server_uri_for_id(id)



87
88
89
# File 'lib/projects/methods.rb', line 87

def server_uri_for_id(id)
  "p4://#{userinfo}#{server}#{safe_hve_projects_path}/#{id}"
end

- (Object) unencode_name(name)



83
84
85
# File 'lib/projects/methods.rb', line 83

def unencode_name(name)
  HWSStrings.component_decode(name)
end

- (Object) userinfo

For HVE Projects, it may be interesting to people to see various connection settings for each server URL.



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/projects/methods.rb', line 105

def userinfo
  data = {}
  if env['hws_settings'].P4CHARSET
    data['P4CHARSET'] = env['hws_settings'].P4CHARSET
  end
  if data.keys.empty?
    ''
  else
    encoded_data = data.map {|k,v| "#{k}=#{v}"}.join(';')
    "#{encoded_data}@"
  end
end