Class: Groundskeeper::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/groundskeeper/project.rb

Overview

Accesses project details stored in the home directory.

Constant Summary collapse

DETAILS_PATH =
"~/.project_details/projects.yml"
SERVERS_PATH =
"~/.project_details/servers.yml"
JIRA_PREFIX_KEY =
"jira_prefix"
PROJECT_NAME_KEY =
"name"
FULL_DNS_KEY =
"full_dns"
RVM_RUBY_VERSION_KEY =
"ruby_version"
SENTRY_DSN_KEY =
"sentry_dsn"
SENTRY_PROJECT_KEY =
"sentry_project"
SMTP_DOMAIN =
"smtp_domain"
SSL_CERTIFICATE_FILE_KEY =
"SSLCertificateFile"
SSL_CERTIFICATE_CHAIN_FILE_KEY =
"SSLCertificateChainFile"
SSL_CERTIFICATE_KEY_FILE_KEY =
"SSLCertificateKeyFile"
WHENEVER_KEY =
"uses_whenever"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(projects_yaml:, servers_yaml:, repository_name:, git: nil) ⇒ Project

:nocov:



42
43
44
45
46
47
48
# File 'lib/groundskeeper/project.rb', line 42

def initialize(projects_yaml:, servers_yaml:, repository_name:, git: nil)
  projects = YAML.safe_load(projects_yaml) || {}
  @details = projects[repository_name] || {}
  @servers = YAML.safe_load(servers_yaml) || {}
  @repo_name = repository_name
  @git = git
end

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



9
10
11
# File 'lib/groundskeeper/project.rb', line 9

def details
  @details
end

#gitObject (readonly)

Returns the value of attribute git.



9
10
11
# File 'lib/groundskeeper/project.rb', line 9

def git
  @git
end

#repo_nameObject (readonly)

Returns the value of attribute repo_name.



9
10
11
# File 'lib/groundskeeper/project.rb', line 9

def repo_name
  @repo_name
end

#serversObject (readonly)

Returns the value of attribute servers.



9
10
11
# File 'lib/groundskeeper/project.rb', line 9

def servers
  @servers
end

Class Method Details

.available_applicationsObject

:nocov:



35
36
37
38
39
# File 'lib/groundskeeper/project.rb', line 35

def self.available_applications
  yaml = Document.new(DETAILS_PATH).read
  projects = YAML.safe_load(yaml) || {}
  projects.keys.join(", ")
end

.build(repository_name) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/groundskeeper/project.rb', line 25

def self.build(repository_name)
  new(
    projects_yaml: Document.new(DETAILS_PATH).read,
    servers_yaml: Document.new(SERVERS_PATH).read,
    repository_name: repository_name,
    git: Git.build
  )
end

Instance Method Details

#deploy_toObject

:nocov:



121
122
123
# File 'lib/groundskeeper/project.rb', line 121

def deploy_to
  "/var/www/apps/#{repo_name}"
end

#full_dns(stage) ⇒ Object



58
59
60
# File 'lib/groundskeeper/project.rb', line 58

def full_dns(stage)
  details.dig(FULL_DNS_KEY, stage.to_s) || ""
end

#jira_prefixObject



54
55
56
# File 'lib/groundskeeper/project.rb', line 54

def jira_prefix
  details[JIRA_PREFIX_KEY] || ""
end

#project_nameObject



50
51
52
# File 'lib/groundskeeper/project.rb', line 50

def project_name
  details[PROJECT_NAME_KEY] || ""
end

#repo_urlObject

:nocov:



115
116
117
# File 'lib/groundskeeper/project.rb', line 115

def repo_url
  git.origin_url
end

#rvm_ruby_versionObject

:nocov:



69
70
71
# File 'lib/groundskeeper/project.rb', line 69

def rvm_ruby_version
  details[RVM_RUBY_VERSION_KEY] || ""
end

#sentry_dsnObject

:nocov:



75
76
77
# File 'lib/groundskeeper/project.rb', line 75

def sentry_dsn
  details[SENTRY_DSN_KEY] || ""
end

#sentry_projectObject

:nocov:



80
81
82
# File 'lib/groundskeeper/project.rb', line 80

def sentry_project
  details[SENTRY_PROJECT_KEY] || ""
end

#server_config(stage) ⇒ Object

:nocov:



109
110
111
# File 'lib/groundskeeper/project.rb', line 109

def server_config(stage)
  servers[full_dns(stage)]
end

#smtp_domainObject

:nocov:



63
64
65
# File 'lib/groundskeeper/project.rb', line 63

def smtp_domain
  details[SMTP_DOMAIN] || ""
end

#ssl_certificate_chain_file(stage) ⇒ Object

:nocov:



91
92
93
# File 'lib/groundskeeper/project.rb', line 91

def ssl_certificate_chain_file(stage)
  details.dig(SSL_CERTIFICATE_CHAIN_FILE_KEY, stage.to_s) || ""
end

#ssl_certificate_file(stage) ⇒ Object

:nocov:



85
86
87
# File 'lib/groundskeeper/project.rb', line 85

def ssl_certificate_file(stage)
  details.dig(SSL_CERTIFICATE_FILE_KEY, stage.to_s) || ""
end

#ssl_certificate_key_file(stage) ⇒ Object

:nocov:



97
98
99
# File 'lib/groundskeeper/project.rb', line 97

def ssl_certificate_key_file(stage)
  details.dig(SSL_CERTIFICATE_KEY_FILE_KEY, stage.to_s) || ""
end

#tagsObject

:nocov:



127
128
129
# File 'lib/groundskeeper/project.rb', line 127

def tags
  git.fetch_and_list_tags
end

#uses_whenever?Boolean

:nocov:

Returns:

  • (Boolean)


103
104
105
# File 'lib/groundskeeper/project.rb', line 103

def uses_whenever?
  details[WHENEVER_KEY] == true
end